110,536
社区成员
发帖
与我相关
我的任务
分享
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
}
....
....
}
<Window x:Class="WPF熊俊.MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
....
....
</Window>
<Window x:Class="WPF熊俊.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPF熊俊">
</Window>
想把Window标签改为local:CustomControl1(CustomControl1是继承自Window的),改不了啊用自定义控件 public class MyWindow : Window
{
static MyWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyWindow), new FrameworkPropertyMetadata(typeof(MyWindow)));
}
public override void OnApplyTemplate()//重写模板
{
base.OnApplyTemplate();
}
//可以重写其他的
}
<Style TargetType="{x:Type local:MyWindow}">
<Setter Property="MinWidth" Value="300"/>
<Setter Property = "MinHeight" Value="300"/>
<Setter Property="ResizeMode" Value="NoResize"/> //这些你应知吧
<Setter Property = "WindowStyle" Value="None"/>
<Setter Property = "Height" Value="760"/>
<Setter Property="Width" Value="1180"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyWindow}">
<Border BorderThickness="2" BorderBrush="#FF007ACC" Background="White">
<Grid>
//设你的头部样式,边框,按钮等等
<Grid>
<ContentPresenter />
</Grid>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="#FF878C8F"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
应用:添加引用生成的DLL
<S:MyWindow x:Class="空间名.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:S="clr-namespace:WpfWin;assembly=WpfWin"
Title="Window2" Height="300" Width="300">
<Grid>
<TextBlock Text="gggggg"></TextBlock>
</Grid>
</S:MyWindow>