110,538
社区成员
发帖
与我相关
我的任务
分享
<base:BaseWindow x:Class="CANConfiger.MainWindow"
...
Style="{StaticResource BaseWindowStyle}">
<Application x:Class="CANConfiger.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CANConfiger"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
...
<ResourceDictionary Source="Style/WindowStyle.xaml"/>
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate TargetType="{x:Type Window}" x:Key="BaseWindowControlTemplateStyle">
<Border Background="White" BorderBrush="Black" BorderThickness="1">
<DockPanel LastChildFill="True">
<Grid VerticalAlignment="Top" HorizontalAlignment="Stretch" DockPanel.Dock="Top">
<StackPanel>
<DockPanel Name="dpTitle" Background="#4C9CFB" Height="60" >
<TextBlock Name="txtTitle" Text="{Binding MainTitle}" Style="{StaticResource AlignmentTitleStyle}" Margin="8,8"/>
<Button Name="btnClose" Content="X" Width="40" Height="40" DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="3,0" />
</DockPanel>
<Image Source="/Resources/公司logo.png" HorizontalAlignment="Left" Height="60" />
</StackPanel>
</Grid>
<AdornerDecorator>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" />
</AdornerDecorator>
</DockPanel>
</Border>
</ControlTemplate>
<Style TargetType="{x:Type Window}" x:Key="BaseWindowStyle">
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="Topmost" Value="False"/>
<Setter Property="Template" Value="{StaticResource BaseWindowControlTemplateStyle}"/>
</Style>
</ResourceDictionary>
public class BaseWindow : Window
{
bool isMaxed = false;
public BaseWindow()
{
this.Loaded += BaseWindow_Loaded;
}
private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
{
if (!DesignerProperties.GetIsInDesignMode(this))
{
ControlTemplate controlTemplate = App.Current.Resources["BaseWindowControlTemplateStyle"] as ControlTemplate;
if (controlTemplate != null)
{
DockPanel dp = controlTemplate.FindName("dpTitle", this) as DockPanel;
dp.MouseMove += dp_MouseMove;
dp.MouseDown += dp_MouseDown;
Button btnClose = controlTemplate.FindName("btnClose", this) as Button;
btnClose.Click += btnClose_Click;
}
MaxWindow();
}
...
<base:BaseWindow x:Class=...
public partial class MainWindow : BaseWindow
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = new MainViewModel();
...
public class MainViewModel : INotifyPropertyChanged
{
public string MainTitle { get { return "XXX v1.0 "; } }
...