Tôi đã chỉnh sửa mẫu từ hộp kiểm, sau đó tôi đã thêm hình ảnh vào mẫu đó mà không xác định thuộc tính "Nguồn" của nó.Truyền thông số vào mẫu tùy chỉnh
Kiểu:
<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>
Câu hỏi của tôi là làm thế nào để vượt qua rằng "Nguồn" tài sản (trong XAML) để "ImageCheckBox" mẫu trong mã này:
<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}">
Vì vậy mà hình ảnh sẽ hiển thị thông số được truyền.
Cảm ơn bạn
Làm thế nào bạn sẽ vượt qua tham số? –
Đây là câu hỏi của tôi :) Tôi muốn chuyển một tham số Nguồn như: Source = "image.ico" tới ImageCheckBox; Vậy làm cách nào để hiển thị thuộc tính Nguồn hình ảnh trong mẫu Hộp kiểm? – Arslan