【发布时间】:2019-05-08 16:04:34
【问题描述】:
我有一个承载样式切换按钮的用户控件。我想使用这个控件并将内容传递给用户控件,如下所示:
用户控制:
<UserControl
x:Class="TouchApp.UI.Views.DieselMotor.DieselToggle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TouchApp.UI.Views.DieselMotor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Name="DieselButton"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="DieselToggleButton" TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid x:Name="RootGrid">
<Ellipse
Margin="6,-49,0,0"
Width="340"
Height="340"
Stroke="Black"
StrokeThickness="2">
<Ellipse.Fill>
<SolidColorBrush Color="{Binding Path=BackColor, ElementName=DieselButton}"/>
</Ellipse.Fill>
</Ellipse>
<ContentPresenter
Content="{TemplateBinding Content}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<ToggleButton
Style="{StaticResource DieselToggleButton}">
<ContentControl Content="{TemplateBinding Content}"/>
</ToggleButton>
</UserControl>
我希望使用用户控件如下:
<local:DieselToggle
BackColor="Aqua"
Command="{Binding SteeringCommand}" CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}">
<StackPanel>
<Image Source="../../../Resources/Diesel/Actuator_off.png"/>
<TextBlock
Style="{StaticResource MainButtonText}"
HorizontalTextAlignment="Center"
x:Uid="buttonSteeringText"/>
</StackPanel>
</local:DieselToggle>
但结果是内容只是显示出来,却没有“传递”到切换按钮。
有没有办法做到这一点?
【问题讨论】: