2

コントロールの背景の一部が透明な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%の透明度の黒で、丸みを帯びた長方形の不透明度マスクの切り欠きがあります。私は通常、このようなものをレンダリングするために画像を使用しますが、グラフィックアーティストはガラスのような効果に夢中になる可能性があります。

4

2 に答える 2

2

Boxあなたのコードには誰がいますか?達成したいことのイメージも追加していただけますか?

欲しいものを手に入れるためにPathsを試しましたか?例:次のパス:

<Path Stroke="Black" Stretch="Fill" StrokeThickness="1" Fill="#CCCCFF">
    <Path.Data>
     <GeometryGroup FillRule="EvenOdd" >
      <EllipseGeometry Center="40,70" RadiusX="30" RadiusY="30" />              
      <RectangleGeometry Rect="30,55 100 30" />
    </GeometryGroup>
  </Path.Data>
</Path>

このカットアウトを提供します: 代替テキストhttp://img704.imageshack.us/img704/928/cutw.jpg

編集:これがあなたのデザインを達成する一つの方法です:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   <Page.Resources>
      <SolidColorBrush x:Key="FillBrush" Color="Gray" Opacity="0.3"/>
   </Page.Resources>
   <Grid>
   <!-- Set background image here, instead of border-->
      <Border>
         <Border.Background>
            <LinearGradientBrush>
               <GradientStop Color="#FFcacaca"/>
               <GradientStop Offset="1" Color="#FF353535"/>
            </LinearGradientBrush>
         </Border.Background>
      </Border>
   <!-- Content goes here -->
      <Grid>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
         </Grid.ColumnDefinitions>
         <Border
            MinHeight="24"
            MinWidth="100"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Background="{StaticResource FillBrush}"
            CornerRadius="15, 0, 0, 15"
            Padding="0, 0, 5, 0">
            <TextBlock
               HorizontalAlignment="Right"
               VerticalAlignment="Center"
               Foreground="White"
               Text="From"/>
         </Border>
         <Border
            MinHeight="24"
            MinWidth="100"
            Grid.Column="1"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            BorderBrush="{StaticResource FillBrush}"
            BorderThickness="1"
            CornerRadius="0, 15, 15, 0">
            <TextBox
               Margin="5, 0, 5, 0"
               VerticalAlignment="Center"
               Background="Transparent"
               BorderThickness="0"
               Foreground="#2f3740"
               Text="Verylongname, Johnathan"/>
         </Border>
      </Grid>
   </Grid>
</Page>

主なポイントは、2つの境界線と1つのブラシを使用することです。ヘッダーフィールドの場合は境界線の背景をペイントし、コンテンツフィールドの場合は境界線の境界線をペイントします:)。

乾杯、アンバカ。

于 2009-12-21T18:23:43.350 に答える
0

作成したパスを使用して、この不透明度マスクを作成しています。

この投稿から、私がマスクとして使用しているオブジェクトを見つけることができます。

奇数形状のジオメトリ

于 2009-12-22T21:15:08.697 に答える