我正在将WPF应用程序移植到WinRT中。这个旧的应用程序有一个部分,它需要一些东西,比如图像、MediaElement、Xaml页面等;将其转换为UIElement;然后接收类会使用VisualBrush将其呈现到按钮上。
不幸的是,WinRT没有VisualBrush。我尝试过将内容设置为UIElement等。我还读到了有关UIElement的文章,但是我认为它不会奏效,因为我也有视频内容。
是否有任何方法可以使控件接受并正确呈现UIElement?
发布于 2015-06-10 12:22:32
根据您想要实现的目标,您只需在UIElement属性中设置您的Button.Content。
Button.Content属性可以接受任何UIElement。
例如,您可以执行以下操作:
MainPage.xaml
<Page ...>
<StackPanel ...>
<Button x:Name="myButton" Width="200" Height="200"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" >
<Button.Content>
<local:Page2 />
</Button.Content>
</Button>
</StackPanel>
</Page>Page2.xaml
<Page...>
<Grid ...>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Fill="Red" />
<Rectangle Fill="Yellow" Grid.Column="1"/>
<Rectangle Fill="Blue" Grid.Row="1"/>
<Button Content="Click Me" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center"/>
</Grid>
</Page>或者从背后的代码:
MainPage.xaml.cs
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
myButton.Content = new Page2();
}
}https://stackoverflow.com/questions/30747909
复制相似问题