Windows phone 7 在windows phone 8中设置禁用按钮的图像
在我的应用程序中,我使用下面的控制模板“图像”按钮 App.xaml中的控件模板如下所示Windows phone 7 在windows phone 8中设置禁用按钮的图像,windows-phone-7,windows-phone-8,imagebutton,Windows Phone 7,Windows Phone 8,Imagebutton,在我的应用程序中,我使用下面的控制模板“图像”按钮 App.xaml中的控件模板如下所示 <!--Below is the style for all ImageButtons in this project --> <Style x:Key="ButtonStyleIB" TargetType="Button"> <Setter Property="Background" Value="Transparent"/> &
<!--Below is the style for all ImageButtons in this project -->
<Style x:Key="ButtonStyleIB" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<!--<Setter Property="Padding" Value="10,3,10,5"/>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="grid" Background="Transparent">
<Grid.Projection>
<PlaneProjection/>
</Grid.Projection>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0" To="-25" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="grid" />
<!--d:IsOptimized="True"-->
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.CenterOfRotationX)" Storyboard.TargetName="grid" />
<!--d:IsOptimized="True"-->
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
因此,根据上述步骤,图像按钮不可单击
但每当按钮被禁用时,我也想更改图像。
我怎样才能做到这一点。不要在按钮中给出图像的直接uri 您可以用字符串属性绑定它,然后单击按钮,您可以将该字符串更改为另一个uri,然后它会将按钮的图像更改为新图像
我希望这会有帮助 您可以使用imagesource绑定来完成。首先像这样定义您的按钮
<Button Grid.Row="1" x:Name="saveButton" Style ="{StaticResource ButtonStyleIB}" VerticalAlignment="Center" Click="saveButton_Click_1" Width="300" Height="50">
<Image Source="{Binding ImageSource}" Stretch="Fill" />
</Button>
public partial class MainPage : PhoneApplicationPage , INotifyPropertyChanged
{
// Constructor
public MainPage()
{
InitializeComponent();
ImageSource = "/Assets/1.jpg";
this.DataContext = this;
}
private string _ImageSource;
public string ImageSource
{
get
{
return _ImageSource;
}
set
{
_ImageSource = value;
FirePropertyChanged("ImageSource");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void FirePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void saveButton_Click_1(object sender, RoutedEventArgs e)
{
ImageSource = "/Assets/2.jpg";
saveButton.IsEnabled = false;
}
}
这里1.jpg和2.jpg是我切换过的图像。我是windows phone开发的新手,请您详细解释一下。您使用的是ViewModel吗??
<Button Grid.Row="1" x:Name="saveButton" Style ="{StaticResource ButtonStyleIB}" VerticalAlignment="Center" Click="saveButton_Click_1" Width="300" Height="50">
<Image Source="{Binding ImageSource}" Stretch="Fill" />
</Button>
public partial class MainPage : PhoneApplicationPage , INotifyPropertyChanged
{
// Constructor
public MainPage()
{
InitializeComponent();
ImageSource = "/Assets/1.jpg";
this.DataContext = this;
}
private string _ImageSource;
public string ImageSource
{
get
{
return _ImageSource;
}
set
{
_ImageSource = value;
FirePropertyChanged("ImageSource");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void FirePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
private void saveButton_Click_1(object sender, RoutedEventArgs e)
{
ImageSource = "/Assets/2.jpg";
saveButton.IsEnabled = false;
}
}