Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在wpf中向usercontrol添加窗口?_C#_Wpf - Fatal编程技术网

C# 如何在wpf中向usercontrol添加窗口?

C# 如何在wpf中向usercontrol添加窗口?,c#,wpf,C#,Wpf,如何将窗口边框添加到WPF中的usercontrol?使用相对源绑定: BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=BorderBrush}" 可以使用Border标记将窗口边框获取到用户控件,如下所示: <UserControl x:Class="WpfApplication1.UserControl1" ------->

如何将窗口边框添加到WPF中的usercontrol?

使用相对源绑定:

BorderBrush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=BorderBrush}"

可以使用
Border
标记将窗口边框获取到用户控件,如下所示:

<UserControl x:Class="WpfApplication1.UserControl1" ------->        
<Border Width="310" CornerRadius="5" BorderBrush="LightBlue"  BorderThickness="1">
<Grid VerticalAlignment="Center">
    <Grid.RowDefinitions>
        <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="40"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Label Content="File" Grid.Column="0" Height="22" Grid.Row="0" ></Label>
    <Button Content="Browse..." Grid.Column="1" Grid.Row="0"  Height="25" Width="70" HorizontalAlignment="Right" Margin="1,1,5,1" SnapsToDevicePixels="True"></Button>
</Grid>
    </Border>
</UserControl>

您可以将用户控件用作窗口的内容

如果您愿意,可以设置窗口的更多属性

 Window w = new Window() {Content=new **YourUserControlHere**,Width=400,Height =400,...  };
w.ShowDialog();

您的意思是向对话框控件添加标题栏和最小/最大/关闭按钮吗?