我是 Windows Phone 8 开发的新手(你可以说知情的菜鸟在寻找答案),我正在寻求解决以下问题的帮助:
我有usercontrol - 更具体地说是一个包含 Image 和 Text 的按钮。我希望该按钮具有以下属性:
- ContentImageNormal - 启用按钮时显示的图像
- ContentImageDisabled - 这将是禁用按钮时显示的图像
我现在拥有的是在我的项目中添加到文件夹 UserControls 中的用户控件,我可以使用它。我为它创建了一个样式并更改了禁用按钮的背景等。
我想知道什么:
- 如何更改代码隐藏和其他所需的东西,以便我可以在下面根据需要使用它?
(我将在我的程序中使用该按钮六次,并且我想将此用户控件用作它的一种模板 - 准备它,所以我只需为这两个状态指定 ImageSources,其余的会做)
期望使用示例:
<UserControls:MainPageButton ContentText="Log In" ContentImageNormal="/ImagePathOrResourceETC.png" ContentImageDisabled="/ImagePathOrResourceETC.png"/>
XAML 我有:
<UserControl x:Class="ProjectNameSpace.UserControls.MainPageButton">
<Grid x:Name="LayoutRoot">
<Button >
<Button.Content>
<Grid>
...omitted...
<Image x:Name="ContentImageHolder" ... />
<TextBlock x:Name="ContentTextBlock" .../>
</Grid>
</Button.Content>
</Button>
</Grid>
</UserControl>
我目前有 C# 代码隐藏:
...usings omitted...
public partial class MainPageButton : UserControl
{
...constructor and text setting omitted for brevity...
public ImageSource ContentImage
{
get
{
return ContentImageHolder.Source;
}
set
{
ContentImageHolder.Source = value;
}
}
}
}