コントロールの背景の一部が透明なUserControlを作成する必要があります。透明部分は、CornerRadiusが2のボーダーの形に切り抜かれています。デザイン上必要です。
これが機能していない私のコードです:
<UserControl Margin="1" x:Name="Box">
<UserControl.Resources>
<Style TargetType="UserControl">
<Setter Property="Height" Value="16" />
</Style>
</UserControl.Resources>
<Grid>
<Border CornerRadius="2" BorderThickness="0">
<Border.Background>
<SolidColorBrush Color="Black" Opacity=".3" />
</Border.Background>
<Border.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<Grid
Background="Black"
Width="{Binding ElementName=Box, Path=ActualWidth}"
Height="{Binding ElementName=Box, Path=ActualHeight}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Margin="1" CornerRadius="2" Background="Transparent" BorderThickness="0" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Border.OpacityMask>
</Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
VerticalAlignment="Center" TextAlignment="Right" FontSize="10" Margin="2"
Foreground="White" Text="Property" />
<TextBlock
Grid.Column="1" VerticalAlignment="Center" TextAlignment="Center" FontSize="10" Margin="2"
Text="Value" />
</Grid>
</Grid>
</UserControl>
いくつか変更を加えたので、これをXamlPadに直接ドロップできるはずです。
何らかの理由で、BorderのOpacityMaskに設定されているVisualBrushがまったく機能していません。OpacityMaskは、すべてが完全に表示されているだけです。テストのために、LinearGradientBrushをすばやくドロップしましたが、期待どおりに機能しました。
VisualBrushとOpacityMaskを一緒に使用する際に問題はありますか?ここで何が問題になっていますか?
これが私が達成しようとしていることのスクリーンショットです:
ScreenShot http://monitor.utopiaselfscan.com/Screen.png
UserControlは、エンティティ番号、進行状況、時間などを示すヘッダーです。これらは30%の透明度の黒で、丸みを帯びた長方形の不透明度マスクの切り欠きがあります。私は通常、このようなものをレンダリングするために画像を使用しますが、グラフィックアーティストはガラスのような効果に夢中になる可能性があります。