【发布时间】:2013-09-26 15:28:22
【问题描述】:
我是 Windows Phone 8 开发的新手(你可以说知情的菜鸟在寻找答案),我正在寻求解决以下问题的帮助:
我有 usercontrol - 更具体地说是一个 包含图像和文本的按钮。我希望该按钮具有以下属性:
- 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;
}
}
}
}
【问题讨论】:
-
虽然我只会使用该按钮六次,但我需要做很多控制,所以这只是我目前最简单的情况。
标签: c# xaml user-controls windows-phone-8