Я хочу создать элемент управления с прозрачным фоном, но мне бы хотелось, чтобы свойство Background определяло некоторые внутренние элементы управления. Так что я могу использовать свойство background.
Обычно я просто привязываю фон к фону UserControl. Но тогда как сделать весь фон управления прозрачным независимо от свойства Background.
<UserControl
x:Class="HLab.Base.DateEx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:base="clr-namespace:HLab.Base"
mc:Ignorable="d" Background="Transparent">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Calendar.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="base:NumTextBox">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="BorderBrush" Value="#80000000"/>
</Style>
<Style TargetType="Label">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1">
<base:NumTextBox
x:Name="TextDay"
MinValue="0"
MaxValue="31"
Background="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Background, Mode=OneWay}"
ValueChanged="OnValueChange"
/><Popup
Name="Popup"
StaysOpen="False">
<Calendar
Name="Calendar"
SelectedDatesChanged="Calendar_OnSelectedDatesChanged"/>
</Popup>
</Grid>
<base:NumTextBox
Margin ="3,0,0,0"
Background="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Background, Mode=OneWay}"
x:Name="TextMonth"
Grid.Column="2"
MinValue="0"
MaxValue="12"
ValueChanged="OnValueChange"
/>
<base:NumTextBox
Margin ="3,0,0,0"
Background="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Background, Mode=OneWay}"
x:Name="TextYear"
Grid.Column="3"
MinValue="0"
MaxValue="9999"
HorizontalContentAlignment="Center"
ValueChanged="OnValueChange"
/>
<Button
Margin ="3,0,0,0"
HorizontalAlignment="Left"
Grid.Column="4"
Name="Button"
Width="15"
Click="Button_OnClick"
Background="Transparent">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<ContentControl Content="{StaticResource Calendar}"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
<Border
x:Name="Mandatory"
Grid.Row="0"
Grid.Column="1"
Visibility="Collapsed"
Grid.ColumnSpan="3" Background="#10FF0010" IsHitTestVisible="False" BorderThickness="1" Opacity="0.5" BorderBrush="DarkRed"/>
<ContentControl x:Name="IconMandatory"
Grid.Row="0" Visibility="Collapsed"
Grid.Column="0"
Margin="5,0,0,0"
IsHitTestVisible="False"
Content="{StaticResource Edit}" Foreground="DarkRed" Height="15"/>
</Grid>
, если я его использую:
<DateEx Background="Red"/>
Мне нужна кнопка не получить красный фон, а только NumTextBoxes.