0

私は単純なバインディングを持っているだけで、うまく機能しますが、エラーポップアップがあります。

エフェクトは動作しますが、まだエラーです。

そして、エラーは System.Windows.Data Error: 2 : ターゲット要素の管理 FrameworkElement または FrameworkContentElement が見つかりません。BindingExpression:(パスなし); DataItem=null; ターゲット要素は 'VisualBrush' (HashCode=23487194) です。ターゲット プロパティは 'Visual' (タイプ 'Visual')

x: Reference を試しましたが、別のエラーが発生します。

役立つものがあれば、大いに感謝します。

<Style TargetType="{x:Type Window}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <Grid>
                            <Border 
                           x:Name="RoundMask"
                           CornerRadius="10"
                           Background="white"/>

                            <!-- The main content -->
                            <Grid>
                                <Grid.OpacityMask>
                                    <VisualBrush Visual="{Binding ElementName=RoundMask}" />
                                </Grid.OpacityMask>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
4

1 に答える 1

0

そのようなウィンドウを再テンプレート化することは、私がこの種のことを行う方法ではありません。

このサンプルのアプローチに似たものを使用します。

https://gallery.technet.microsoft.com/ThWPFPolishing-Chrome-f41be7fe

完成したファンシーウィンドウは ここに画像の説明を入力

リソース ディクショナリ Dictionary1 にある WindowChrome スタイルを使用する Window6。

大きな丸い閉じるボタンのようなものがあります。ただし、ダウンロードする前にアイデアを提供するために:

<Style x:Key="FinishedWindow" TargetType="{x:Type Window}">
    <Setter Property="FontFamily" Value="Comic Sans MS"/>
    <Setter Property="Foreground" Value="{StaticResource DarkDark}"/>
    <Setter Property="WindowChrome.WindowChrome">
        <Setter.Value>
            <WindowChrome CaptionHeight="0"
                          CornerRadius="20"
                          GlassFrameThickness="0"
                          NonClientFrameEdges="None"
                          ResizeBorderThickness="5"
                                    />
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Grid>
                    <Border   Background="{StaticResource BrightMid}"   BorderBrush="{StaticResource DarkLight}" BorderThickness="4,4,6,6" 
                         CornerRadius="12">
                        <Border.Effect>
                            <BlurEffect  KernelType="Gaussian" Radius="12" RenderingBias="Quality" />
                        </Border.Effect>
                    </Border>
                    <Border BorderBrush="{StaticResource DarkDark}" BorderThickness="2" 
                            CornerRadius="12" ClipToBounds="True">
                    </Border>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="32"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                                          Foreground="{StaticResource DarkDark}"
                                          Grid.Row="0"
                                          HorizontalAlignment="Center" 
                                          VerticalAlignment="Bottom"
                                          FontWeight="Bold"
                                          FontSize="16"
                                     />
                        <Button Name="CloseButton" 
                                Width="20" Height="20"   
                                Grid.Row="0"
                                HorizontalAlignment="Right"
                                BorderThickness="0"
                                Margin="0,12,12,0"
                                Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CloseCommand}"
                                Style="{StaticResource CloseButton}"/>
                        <ContentPresenter Grid.Row="1" Margin="12"/>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter> 

あなたのスタイルを試してみました。

暗黙的に使用するだけでは、まったく効果がありませんでした。

それを app.xaml に入れてキーを与えました

<Application.Resources>
    <Style TargetType="{x:Type Window}" x:Key="roundedWindowStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Grid>
                        <Border 
                       x:Name="RoundMask"
                       CornerRadius="10"
                       Background="white"/>

                        <!-- The main content -->
                        <Grid>
                            <Grid.OpacityMask>
                                <VisualBrush Visual="{Binding ElementName=RoundMask}" />
                            </Grid.OpacityMask>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

そして、それをメインウィンドウに適用しました

<Window
    ...
    Title="MainWindow" 

    Style="{StaticResource roundedWindowStyle}"

f5 を押すと、うまくいきます。良い。

そのウィンドウクロムを無視すると、意図したとおりに機能しないことを意味します。

ここに画像の説明を入力

おそらく、代わりに window chrome を使用することを検討する必要があります。

あなたがそこに持っているもので。

最低限、そのグリッド内に Contentpresenter が必要です。ウィンドウはコンテンツ コントロールですが、テンプレートに contentpresenter がない場合、コンテンツはまったく表示されません。

于 2019-03-09T10:52:21.163 に答える