我有用户控制权,想通过点击wpf设计的窗口中的按钮来显示它。 我创建了一个控件用户项目,并以这种方式在wpf项目中引用它:
xmlns:myproj="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
并在<Grid>
标签中我有这个:
<myproj:UserControl1 Visibility="Hidden"
x:Name="customproj" />
正如我告诉我在wpf项目的主窗口中有一个按钮:
<Button Content="click me" HorizontalAlignment="Left" Margin="186,127,0,0" VerticalAlignment="Top" Width="124" Height="31" Click="Button_Click"/>
但我不知道如何编写Button_Click
的事件来打开控件用户。
private void Button_Click(object sender, RoutedEventArgs e)
{
//I don't know what to write!!!
}
我搜索了很多,但没有为我的问题找到合适的答案!
谢谢
答案 0 :(得分:3)
只需将UserControl的 Visibility
设置为 Visible
:
private void Button_Click(object sender, RoutedEventArgs e)
{
customproj.Visibility = Visibility.Visible;
}