XAML, .
, Source WPF. , , , , Content Button , App.xaml( )
, , , , - . , , , ( , ). , , ,
, , ChangePnumTextState, , ? bool IsPnumLocked, XAML .
Canvas, :
<Button Command="{Binding ChangePnumTextState}">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsPNumLocked}" Value="True">
<Setter Property="Content" Value="{StaticResource appbar_lock}"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsPNumLocked}" Value="False">
<Setter Property="Content" Value="{StaticResource appbar_unlock}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
, , , , .
RelativeSource datacontext ( , , )
:
bool ( IsPNumLocked). , .
:
public class IsPnumLockedToCanvasPathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool val = (bool)value;
return val
? "F1 M 22.17,36.4216L 25.3369,36.4216L 25.3369,31.6711C 25.3369,24.6745 31.0087,19.0027 38.0053,19.0027C 45.0019,19.0027 50.6737,24.6745 50.6737,31.6711L 50.6737,36.4216L 53.841,36.4216L 53.8411,57.008L 22.17,57.008L 22.17,36.4216 Z M 45.9231,31.6711C 45.9231,27.2982 42.3782,23.7533 38.0053,23.7533C 33.6324,23.7533 30.0875,27.2982 30.0875,31.6711L 30.0875,36.4216L 45.923,36.4216L 45.9231,31.6711 Z "
: "F1 M 22.1698,36.4215L 25.3366,36.4215L 25.3367,31.6711C 25.3367,24.6745 31.0085,19.0027 38.0051,19.0027C 45.0017,19.0027 50.6735,24.6745 50.6735,31.6711L 45.9228,31.6711C 45.9228,27.2982 42.3779,23.7533 38.0051,23.7533C 33.6322,23.7533 30.0873,27.2982 30.0873,31.6711L 30.0873,36.4216L 53.8408,36.4215L 53.8409,57.008L 22.1698,57.008L 22.1698,36.4215 Z ";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
:
<Button Command="{Binding ChangePnumTextState}">
<Button.Resources>
<converters:IsPnumLockedToCanvasPathConverter x:Key="IsPnumLockedToCanvasPathConverter"/>
</Button.Resources>
<StackPanel Orientation="Vertical">
<Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0">
<Path Width="40" Height="40" Canvas.Left="18" Canvas.Top="18" Stretch="Fill" Fill="{DynamicResource BlackBrush}" Data="{Binding IsPNumLocked, Converter={StaticResource IsPnumLockedToCanvasPathConverter}}"></Path>
</Canvas>
<TextBlock Text="Other Content"/>
</StackPanel>
</Button>