简体   繁体   English

WPF WindowChrome ContentPresenter 不显示内容

[英]WPF WindowChrome ContentPresenter does not display content

When I try to display content from the ContentPresenter I cannot see anything.当我尝试从ContentPresenter显示内容时,我什么也看不到。 The test block does not display any text and it seems to be hidden.测试块不显示任何文本,它似乎被隐藏了。

<local:ResizableVideoHostWindow x:Class="TestClass"
        x:ClassModifier="internal"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:shell="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        mc:Ignorable="d"
        Title="{Binding Title}">

    <Window.Style>
        <Style TargetType="{x:Type local:ResizableVideoHostWindow}">
            <Setter Property="WindowChrome.WindowChrome">
                <Setter.Value>
                    <shell:WindowChrome
                        CaptionHeight="30"
                        CornerRadius="1"
                        GlassFrameThickness="0,0,0,-1"
                        NonClientFrameEdges="None"
                        ResizeBorderThickness="5"
                        UseAeroCaptionButtons="true"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:ResizableVideoHostWindow}">
                        <Grid x:Name="AppTitleBar" Background="Transparent" VerticalAlignment="Top">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
                                </Grid.ColumnDefinitions>

                                <Button
                                    Background="Transparent"
                                    Visibility="Visible"
                                    BorderThickness="0"
                                    Grid.Column="1"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    Width="20"
                                    Height="20"
                                    Margin="8,2,0,0"
                                    shell:WindowChrome.IsHitTestVisibleInChrome="True">

                                    <TextBlock Text="&#xE72B;" FontFamily="Segoe MDL2 Assets">
                                    </TextBlock>
                            </Button>

                                <TextBlock
                                    FontFamily="Segoe UI"
                                    Grid.Column="1"
                                    Height="20"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    TextAlignment="Center" 
                                    Margin="35,4,0,0"
                                    Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />

                                <Button
                                    Background="Transparent"
                                    Visibility="Visible"
                                    BorderThickness="0"
                                    Grid.Column="1"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    Margin="0,0,160,0"
                                    Width="30"
                                    Height="30"
                                    shell:WindowChrome.IsHitTestVisibleInChrome="True">

                                    <TextBlock Text="&#xE712;" FontFamily="Segoe MDL2 Assets">
                                    </TextBlock>
                            </Button>
                            <ContentPresenter Grid.Row="1"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="WindowState" Value="Maximized">
                    <Setter Property="BorderThickness" Value="7" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Style>

    <Grid Visibility="Visible">
        <TextBlock Text="Test Block" FontSize="20" >
        </TextBlock>

        <local:AppProxyContainer
            DataContext="{Binding ContainerViewModel}" />
    </Grid> 

</local:ResizableVideoHostWindow>

I am mainly confused on how to display the content.我主要对如何显示内容感到困惑。 I have seen other posts stating that this method of using ContentPresenter works, but it does not work for me.我看到其他帖子说这种使用ContentPresenter的方法有效,但它对我不起作用。

You use the ContentPresenter correctly, but you do not set its column in the Grid , so it will be placed in the LeftPaddingColumn column, which has zero Width .您正确使用了ContentPresenter ,但没有在Grid中设置它的列,因此它将被放置在Width为零的LeftPaddingColumn列中。

<Grid.ColumnDefinitions>
   <ColumnDefinition x:Name="LeftPaddingColumn" Width="0"/>
   <ColumnDefinition/>
   <ColumnDefinition x:Name="RightPaddingColumn" Width="0"/>
</Grid.ColumnDefinitions>

Set its attached Grid.Column property to 1 , so it will be displayed in the second column, which sizes to the remaining space.将其附加的Grid.Column属性设置为1 ,因此它将显示在第二列中,该列的大小与剩余空间相同。

<ContentPresenter Grid.Row="1" Grid.Column="1"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM