在我的项目中,我已修复页眉&页脚和可更改的内容。所以我把ContentControl放在了我的窗口中。如何更改WPF中的内容控件内容?
<Grid>
<Canvas Name="canvas_Logo" HorizontalAlignment="Center" VerticalAlignment="Top" Width="180">
<Image Source="Images/k1.png" Grid.Row="1" Width="180" />
</Canvas>
<ContentControl VerticalAlignment="Center" Name="CC1" Grid.Row="2" Height="450"/>
<Canvas x:Name="canvas_Marque" ClipToBounds="True" Height="60" HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="1022" Background="DarkRed" />
</Grid>
它看起来就像这样......
我已创建两个用户控件的名称第1页,第2页。第1页有一个按钮,当我点击按钮时,ContentControl显示page2。
,所以我有写的button1_Click
MainPage n = new MainPage();
n.CC1.Content = new Page2();
但在按键的时候下面的代码,点击ContentControl中没有改变我能为这做什么?
我的第1页XAML
<Grid Background="AliceBlue">
<Label Content="Child1" Height="28" HorizontalAlignment="Left" Margin="74,65,0,0" Name="label1" VerticalAlignment="Top" Width="157" />
<Button Content="load page2 and destroy this" Height="31" HorizontalAlignment="Left" Margin="79,124,0,0" Name="button1" VerticalAlignment="Top" Width="186" Click="button1_Click" />
</Grid>
第2页XAML
<Grid Background="CadetBlue">
<Label Content="This is page 2" Height="28" HorizontalAlignment="Left" Margin="96,82,0,0" Name="label1" VerticalAlignment="Top" Width="148" />
</Grid>
如何改变在WPF的内容控制内容?
http://stackoverflow.com/questions/16855352/changing-content-dynamically-in-wpf-window在这里,我得到了这个想法。它看起来很简单。你可以请通过并为我的问题提供一个简单的解决方案。 – Sagotharan
这与您之前的问题[我的回答](http://stackoverflow.com/a/20113543/1698987)完全相同。你所要做的就是按照我的建议使用它,而我的屏幕截图显示了那里的结果(用户控件只有一个带有蓝色背景的标签,表示“来自用户控件的嗨”)。 – Noctis