将圆角设置为Windows视图

时间:2018-05-16 21:42:46

标签: c# xaml

我正在尝试添加圆形窗口,以便从中查看视图:enter image description here

对此:enter image description here

网上有一些类似的问题表示将WindowStyle更改为NoneAllowsTransparency=True并使用Border标记,如下所示。

<Window x:Class="SIDD.EmailComposerWindow"
    ...

    Height="460.316" 
    Width="733.167"
    WindowStartupLocation="CenterScreen"
    WindowStyle="None"
    AllowsTransparency="True"
    ResizeMode="CanResize"

   <Border Background="White" BorderBrush="Black" BorderThickness="1,1,1,1" CornerRadius="30,30,30,30">
    <Grid>
    </Grid>
</Border>
>
<Window.Background>
    <SolidColorBrush Opacity="0" />


</Window.Background>
<WindowChrome.WindowChrome>
    <WindowChrome CaptionHeight="{Binding ActualHeight,ElementName=TitleBar}"
                    GlassFrameThickness="0"
    />
</WindowChrome.WindowChrome>
<Window.DataContext>
    <localvm:EmailComposerViewModel />
</Window.DataContext>

<Window.Style>
    <Style TargetType="{x:Type Window}">
        <Setter Property="Background" Value="{StaticResource WindowBrush}"/>
    </Style>
</Window.Style>

<Window.Resources>
    <SolidColorBrush x:Key="WindowBrush" Color="White"/>
    <Style x:Key="VerticalSeparatorStyle" 
   TargetType="{x:Type Separator}"
   BasedOn="{StaticResource {x:Type Separator}}">
        <Setter Property="Margin" Value="6,0,6,0"/>
        <Setter Property="LayoutTransform">
            <Setter.Value>
                <TransformGroup>
                    <TransformGroup.Children>
                        <TransformCollection>
                            <RotateTransform Angle="90"/>
                        </TransformCollection>
                    </TransformGroup.Children>
                </TransformGroup>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="ButtonLinkStyle" TargetType="Button">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Margin" Value="2,4,2,4" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="border" BorderThickness="0" BorderBrush="Transparent">
                        <ContentPresenter HorizontalAlignment="Center"  VerticalAlignment="Center" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="border" Value="White"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Foreground" Value="DarkGoldenrod"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <BooleanToVisibilityConverter x:Key="BoolToVis"/>
    <Style x:Key="SearchButton" TargetType="{x:Type Button}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Margin" Value="2,4,2,4" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Border x:Name="border" BorderThickness="0" BorderBrush="Transparent">
                        <ContentPresenter HorizontalAlignment="Center"  VerticalAlignment="Center" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="border" Value="White"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Foreground" Value="DarkGoldenrod"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Image x:Key="SearchIcon" Source="../Images/Search.png" Height="15px" Width=" 15px"/>
    <Image x:Key="ResetIcon" Source="../Images/CancelX.png"  Height="15px" Width="15px"/>
    <Style x:Key="PaneBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="CornerRadius" Value="10,10,10,10"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Margin" Value="0,0,0,0"/>
        <Setter Property="Background" Value="WhiteSmoke"/>
    </Style>
</Window.Resources>


<!-- Content Layout -->
<DockPanel Margin="10,10,10,10">

    <!-- Header -->
    <Border Background="Blue" Style="{DynamicResource PaneBorderStyle}" CornerRadius="15,15,0,0">
        <Grid>
            <TextBlock  HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="textBlock_From"  Width="283" />

        </Grid>
    </Border>


    <!-- Body -->
    <Grid DockPanel.Dock="Top">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="77*"/>
            <ColumnDefinition Width="64*"/>
            <ColumnDefinition Width="141*"/>
            <ColumnDefinition Width="140*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
        </Grid.RowDefinitions>

        <!-- Left panel -->
        <Border Style="{DynamicResource PaneBorderStyle}" Margin="0,0,0,0" Grid.ColumnSpan="2" >
            <DockPanel VerticalAlignment="Top">

                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <Label VerticalAlignment="Center" Content="Email from:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.CustomerName}" />
                </StackPanel>

                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <Label Content="Case:" OpacityMask="Black" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.CaseDetails}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" VerticalAlignment="Top" DockPanel.Dock="Top">
                    <Label Content="Account Details:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.AccountInfo}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <Label Content="Date:" Opacity="0.6" FontFamily="Levenim MT" Width="100" />
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.MessageDate}" />
                </StackPanel>
                <Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2" Margin="0,5,0,5"/>
                <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" Text="{Binding Ticket.MessageContent}" TextWrapping="Wrap" DockPanel.Dock="Top" />

            </DockPanel>

        </Border>

        <!-- Center panel -->
        <Border Style="{DynamicResource PaneBorderStyle}" CornerRadius="10,0,0,10" Grid.Column="2" Background="White" Width="Auto">
            <DockPanel LastChildFill="True">
                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <Label VerticalAlignment="Center" Content="To" Opacity="0.6" FontFamily="Levenim MT" Margin="5,0,0,0" />
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="#E8F2FF" Text="{Binding Ticket.CustomerEmailAddress}" FontSize="12" VerticalAlignment="Center" />
                </StackPanel>
                <Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2"/>
                <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
                    <Label Content="Subject" Opacity="0.6" FontFamily="Levenim MT" Margin="5,0,0,0"/>
                    <TextBox BorderThickness="0" IsReadOnly="True" Background="Transparent" VerticalAlignment="Center" Text="{Binding Ticket.Subject}" />
                </StackPanel>
                <Rectangle Fill="#FFF4F4F5" Stroke="Black" DockPanel.Dock="Top" Opacity="0.2"/>

                <ToolBar Margin="2" Background="LightGray" DockPanel.Dock="Top" Visibility="Collapsed">
                    <Button>1</Button>
                    <Button>2</Button>
                    <Button>3</Button>
                    <Button>4</Button>
                    <ComboBox SelectedIndex="0">
                        <ComboBoxItem>Style1</ComboBoxItem>
                        <ComboBoxItem>Style2</ComboBoxItem>
                        <ComboBoxItem>Style3</ComboBoxItem>
                    </ComboBox>
                    <Button>5</Button>
                    <Button>6</Button>
                    <Separator />
                    <Button>7</Button>
                    <Button>8</Button>
                    <Separator />
                    <Button>9</Button>
                    <Button>10</Button>
                </ToolBar>

                <RichTextBox Name="EditMessageBox" Margin="5,0,5,5" DockPanel.Dock="Top" Height="auto" BorderThickness="5" BorderBrush="{x:Null}" Background="White">
                    <RichTextBox.Resources>
                        <Style TargetType="{x:Type Paragraph}">
                            <Setter Property="Margin" Value="0" />
                        </Style>
                    </RichTextBox.Resources>
                </RichTextBox>
            </DockPanel>
        </Border>

        <!-- Right panel -->
        <Border Style="{DynamicResource PaneBorderStyle}" CornerRadius="0,10,10,0" Grid.Column="3">
            <Grid Margin="2">
                <DockPanel LastChildFill="True" RenderTransformOrigin="0.5,0.5">

                    <!-- suggestions -->
                    <Label Content="SUGGESTIONS" HorizontalAlignment="Left" DockPanel.Dock="Top" FontFamily="Levenim MT" Margin="0" Width="90.277" Opacity="0.6" />

                    <!-- snippet list -->
                    <Grid Height="Auto" x:Name="SnippetViewGrid">
                        <StackPanel x:Name="AccordianStack" Margin="0,0,0,10">
                            <!--Snippet Categories-->
                            <ItemsControl  ItemsSource="{Binding ObservableSnippetCategories}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <custom:Accordian x:Name="Accordian" ButtonClick="Accordian_ButtonClick"
                                                          TemplateSelectCommand="{Binding TemplateSelectCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
                                                          TemplateShowCommand="{Binding TemplateShowCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}">
                                        </custom:Accordian>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>

                        </StackPanel>
                    </Grid>
                </DockPanel>

                <!-- Searchbar -->
                <DockPanel Margin="5,5,5,5" LastChildFill="True" Height="35.667" VerticalAlignment="Bottom">
                    <Border Margin="0,4,0,0" Width="Auto" CornerRadius="5,5,5,5" Background="White" BorderThickness="1" BorderBrush="Gray">
                        <Grid>
                            <Button x:Name="SearchTemplateButton" Content="{StaticResource SearchIcon}" 
                                    Command="{Binding SearchTemplatesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
                                    CommandParameter="{Binding Text, ElementName=SearchKey}"
                                    Style="{StaticResource ButtonLinkStyle}" Opacity="0.5" HorizontalAlignment="Left" VerticalAlignment="Center"
                            />
                            <TextBox x:Name="SearchKey" Text="" BorderThickness="0" Width="Auto" Background="White" Margin="21.724,4,20.999,4">
                                <TextBox.InputBindings>
                                    <KeyBinding Key="Enter"
                                                Command="{Binding SearchTemplatesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
                                                CommandParameter="{Binding Text, ElementName=SearchKey}"
                                                />
                                    <KeyBinding Key="Esc"
                                                Command="{Binding ResetSearchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
                                                />
                                </TextBox.InputBindings>
                            </TextBox>
                            <Button x:Name="ResetSearchButton" Content="{StaticResource ResetIcon}"
                                    Command="{Binding ResetSearchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:EmailComposerWindow}}}"
                                    Style="{DynamicResource SearchButton}" Opacity="0.5" Width="18.999" Height="Auto"
                         Margin="0,4,2,4" HorizontalAlignment="Right" VerticalAlignment="Center"
                         />
                        </Grid>
                    </Border>
                </DockPanel>
            </Grid>
        </Border>

    </Grid>

</DockPanel>

但是,使用此添加的代码,我收到以下代码的错误The property content is set more than once

  <!-- Header -->
    <Border Background="Transparent" DockPanel.Dock="Top" x:Name="TitleBar">
        <DockPanel LastChildFill="True" Margin="0,0" HorizontalAlignment="Center" DockPanel.Dock="Top" Height="20">
        </DockPanel>
    </Border>

有谁知道这是为什么?

1 个答案:

答案 0 :(得分:0)

您在此处设置了两倍的窗口样式:

<Window.Style>
<Style TargetType="{x:Type Window}">
    <Setter Property="Background" Value="{StaticResource WindowBrush}"/>
</Style>

在这里:

   WindowStyle="None"

我现在不接近VS,但似乎是问题所在。