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

时间:2010-08-20 12:45:39

标签: c# wpf

如何在WPF中向用户控件添加窗口边框?

3 个答案:

答案 0 :(得分:0)

使用相对源绑定:

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

答案 1 :(得分:0)

您可以使用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>

答案 2 :(得分:0)

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

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

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

CheckHere