C# WP7中带有图像的消息框
您好,目前我正在使用一个带有图像的网格和两个按钮来显示我的WP7应用程序中的自定义消息框,该消息框的可见性首先被折叠。一切正常,但当页面的可见性可见时,我必须禁用页面上的所有控件。因此,启用/禁用后面的许多控制是相当大的开销C# WP7中带有图像的消息框,c#,.net,silverlight,windows-phone-7,C#,.net,Silverlight,Windows Phone 7,您好,目前我正在使用一个带有图像的网格和两个按钮来显示我的WP7应用程序中的自定义消息框,该消息框的可见性首先被折叠。一切正常,但当页面的可见性可见时,我必须禁用页面上的所有控件。因此,启用/禁用后面的许多控制是相当大的开销 有一个更好的解决方案,我的要求是:(1)显示一个有图像和两个按钮或文本框的消息框,(2)它应该出现在页面中间。 提前谢谢 您可以使用内置的、由编写的附加行为,因此它的行为类似于WPF弹出控件,带有PlacementTarget和Placement: <Popup b:
有一个更好的解决方案,我的要求是:(1)显示一个有图像和两个按钮或文本框的消息框,(2)它应该出现在页面中间。
提前谢谢 您可以使用内置的、由编写的附加行为,因此它的行为类似于WPF弹出控件,带有PlacementTarget
和Placement
:
<Popup b:PopupPlacement.PlacementTarget="{Binding ElementName=someElement}">
<b:Popup.PreferredOrientations>
<b:PopupOrientationCollection>
<b:PopupOrientation Placement="Top" HorizontalAlignment="Center"/>
<b:PopupOrientation Placement="Bottom" HorizontalAlignment="Center"/>
<b:PopupOrientation Placement="Right" VerticalAlignment="Center"/>
<b:PopupOrientation Placement="Right" VerticalAlignment="TopCenter"/>
</b:PopupOrientationCollection>
</b:Popup.PreferredOrientations>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0">My popup's contents</TextBlock>
<Image Grid.Row="1" .... />
</Grid>
</Popup>
我的弹出窗口的内容
- 见文章
除了标准的Silverlight toolkit之外,该工具包还有许多可用的控件,应该能够满足您的需要。试试这一个,可能会对您有所帮助
StackPanel st = new StackPanel();
StackPanel st1 = new StackPanel();
Image image = new Image();
image.Height = 300;
image.Width = 300;
image.Source = new BitmapImage(new Uri("/PhoneApp1;component/Koala.jpg", UriKind.Relative));//Build Action=Resource
Button btnok = new Button();
btnok.Content = "Ok";
btnok.Click += new RoutedEventHandler(btnok_Click);
Button btncancel = new Button();
btncancel.Content = "Cancel";
btncancel.Click += new RoutedEventHandler(btncancel_Click);
st1.Orientation = System.Windows.Controls.Orientation.Horizontal;
st1.Children.Add(btnok);
st1.Children.Add(btncancel);
st.Children.Add(image);
st.Children.Add(st1);
ContentPanel.Children.Add(st);
在这种情况下,我要做的是向页面添加一个网格或边框,该页面有一个透明的背景,并且ishitestvisible=True。然后可以将图像等添加到父控件(网格/边框)。 您需要确保父控件覆盖整个页面,然后将对话框置于该控件的中心。切换父控件的可见性时,透明背景将覆盖页面上的其他控件,从而有效地禁用它们 这里有一个例子。uxMessageGrid是父控件,边框是实际对话框。然后,您只需确保这是添加到根元素的最后一个控件,并在代码中切换uxMessageGrid.Visibility
<Grid x:Name="uxLayoutRoot">
<Other Controls />
<Grid x:Name="uxMessageGrid"
Visibility="Collapsed"
Background="Transparent"
IsHitTestVisible="True">
<Border CornerRadius="0"
BorderThickness="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
BorderBrush="{StaticResource PhoneForegroundBrush}"
Background="{StaticResource PhoneBackgroundBrush}">
<TextBlock Margin="15"
Text="Message..."
TextWrapping="Wrap"/>
</Border>
</Grid>
</Grid>
对不起,sll,我下载了该项目,但我认为它只适用于浏览器,不适用于wp7 silverlight,因此我无法运行它,因为我现在只安装了windows phone工具。我想问一下,wp7是否也支持这个弹出窗口,它是否会在弹出窗口时自动禁用它后面的所有元素(控件)。无论如何,你可以用同样的方式使用附加行为。我相信这个弹出控件也应该在WP7中工作