我有一个带有图像和文字的自制按钮。
<ButtonImageApp:ButtonImage
BText="Button"
这工作正常。但是当我尝试绑定时,我的按钮代码被破坏了。
这行不通。
BText="{Binding Path=LocalizedResources.PlayButton, Source={StaticResource LocalizedStrings}}"
XAML
<Button x:Class="ButtonImageApp.ButtonImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
IsEnabledChanged="ButtonIsEnabledChanged"
MouseEnter="ButtonMouseEnter"
MouseLeave="ButtonMouseLeave">
<Grid>
<Image Stretch="None"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Grid.Row="0" Grid.Column="0"
x:Name="image" />
<TextBlock x:Name="txtButtonText"
Foreground="Black"
Text="{Binding Path=BText}"
Grid.Row="0" Grid.Column="0"
Margin="20,51,0,-51" TextAlignment="Center"></TextBlock>
</Grid>
</Button>
编码:
public static readonly DependencyProperty ButtonText = DependencyProperty.Register("BText", typeof(string), typeof(ButtonImage), null);
public string BText
{
get { return (string)GetValue(ButtonText); }
set
{
SetValue(ButtonText, value);
txtButtonText.Text = value;
}
}