如何在WPF中更改窗口样式?

时间:2013-11-28 13:13:27

标签: c# wpf styles dialog

我是WPF的新手,我需要自定义一个如下所示的窗口:

http://i41.tinypic.com/2dtb0hh.jpg http://i41.tinypic.com/2dtb0hh.jpg

默认模型是:

http://i42.tinypic.com/r76lno.jpg http://i42.tinypic.com/r76lno.jpg

我想知道要使用什么,以及互联网上是否有任何教程可以帮助我实现这一目标。我搜索了互联网但我找不到任何类似于我想要实现的东西。

2 个答案:

答案 0 :(得分:1)

以下示例创建了一个请求的WPF窗口。

备注:

  1. WindowStyle属性设置为"无"隐藏标准OS chrome
  2. 以下示例中引用的图片未包含在内
  3. 需要为"是"处理Click Event。和"不"按钮
  4. <Window x:Class="CustomConfirmBox.ConfirmBox"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="ConfirmBox" Height="275" Width="376"
            WindowStyle="None" >
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="38" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border Grid.Row="0" Background="CornflowerBlue" >
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" >
            <Image x:Name="ConfirmIcon" Margin="6" Source="Icon.jpg" />
            <TextBlock Text="Confirmation" VerticalAlignment="Center" FontSize="20" Foreground="White" />
          </StackPanel>
        </Border>
        <Grid Grid.Row="1">
          <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="63"/>
          </Grid.RowDefinitions>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="35" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="35" />
          </Grid.ColumnDefinitions>
          <TextBlock Grid.Row="0" Grid.Column="1" TextWrapping="Wrap" HorizontalAlignment="Center"
                     LineStackingStrategy="BlockLineHeight" LineHeight="30" TextAlignment="Center" Margin="0,20" >
            Meter data and logs are deleted from the application immediately once
            archiving is complete, while structures are kept in the application.
          </TextBlock>
          <TextBlock Grid.Row="1" Grid.Column="1" TextAlignment="Center" Margin="6" >
            Are you sure you want to continue?
          </TextBlock>
          <Grid Grid.Row="2" Grid.Column="1" >
            <Grid.RowDefinitions>
              <RowDefinition Height="*" />
              <RowDefinition Height="Auto" />
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button Grid.Row="1" Grid.Column="1" x:Name="ButtonYes" Content="Yes"
                    Background="White" Height="25" Width="73" BorderBrush="LightGray" />
            <Button Grid.Row="1" Grid.Column="4" x:Name="ButtonNo" Content="No"
                    Background="White" Height="25" Width="73" BorderBrush="LightGray" />
          </Grid>
        </Grid>
      </Grid>
    </Window>
    

答案 1 :(得分:0)

WPF的优点在于,您可以使用自定义样式设置几乎所有内容。如果你使用混合,你可以很容易地开始,通过右键单击一个控件并选择样式 - &gt;创建模板 - &gt;创建副本。主题本身非常大,所以我会给你一些教程来帮助你入门: