我從複選框編輯了模板,然後向其中添加了一個圖像,但未定義其「源」屬性。將參數傳遞給自定義模板
風格:
<Style x:Key="ImageCheckbox" TargetType="{x:Type CheckBox}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="{StaticResource CheckBoxFillNormal}"/>
<Setter Property="BorderBrush" Value="{StaticResource CheckBoxStroke}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource EmptyCheckBoxFocusVisual}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Image x:Name="image" Width="20" Height="20" Stretch="UniformToFill"/>
<ControlTemplate.Triggers>
<Trigger Property="HasContent" Value="true">
<Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
<Setter Property="Padding" Value="4,0,0,0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的問題是如何傳遞 「源」 屬性(在XAML)爲 「ImageCheckBox」 模板,在此代碼:
<CheckBox Content="" Margin="0,2,0,0" Name="btTogglePalette" Grid.Row="1" Command="Helpers:UICommands.TogglePalette"
IsChecked="{Binding Path=PaletteStatus, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"
Style="{DynamicResource ImageCheckbox}">
,使圖像將顯示傳遞的參數。
謝謝
你將如何傳遞參數? –
這是我的問題:)我想通過Source參數,如:Source =「image.ico」ImageCheckBox;所以如何在CheckBox模板中公開Image Source屬性? – Arslan