Доброго времени суток всем!
Товарищи, есть вопрос по Windows Phone 7!
Необходимо создать пользовательский компонент, кнопку CustomButton, в котором в качестве фона служит картинка. При нажатии на кнопку картинка меняется на другую, символизирующую состояние Pressed. Этот компонент я хотел создать в отдельной сборке.
ОЧЕНЬ ВАЖНО: путь к картинкам должен быть настраиваемым из кода, использующего данный компонент, то есть прописать в xaml-файле компонента что-то типа Source="Image1.png" совершенно не подходит!
В C# классе компонента хочу создать два строковых свойства отвечающие за картинки:
А в xaml файле компонента каким-то образом описать поведение моего компонента в состояниях Pressed и Normal, чтобы это выглядело примерно так:Code:public class DKButton: Button { public DKButton() { DefaultStyleKey = typeof(DKButton); } public static readonly DependencyProperty UriNormalStateProperty = DependencyProperty.Register( "UriNormalState", typeof(String), typeof(DKButton), null ); public String UriNormalState { get { return (String)GetValue(UriNormalStateProperty); } set { SetValue(UriNormalStateProperty, value); } } public static readonly DependencyProperty UriPressedStateProperty = DependencyProperty.Register( "UriPressedState", typeof(String), typeof(DKButton), null ); public String UriPressedState { get { return (String)GetValue(UriPressedStateProperty); } set { SetValue(UriPressedStateProperty, value); } } }
Но вот каким образом мне это прописать в xaml файле я не имею представления, так как с Silverlight до настоящего момента был не знаком. Не могли бы подсказать?Code:<ControlTemplate TargetType="src:DKButton"> <Grid x:Name="RootElement"> <Image Name="backgroundImage" /> <vsm:VisualStateManager.VisualStateGroups> <!--Define the states for the common states. The states in a VisualStateGroup are mutually exclusive to each other.--> <vsm:VisualStateGroup x:Name="CommonStates"> <!--Define the VisualStates in this VistualStateGroup.--> <vsm:VisualState x:Name="Normal" backgroundImage.Source = UriNormalState/> button is pressed.--> <vsm:VisualState x:Name="Pressed" backgroundImage.Source = UriPressedState /> </vsm:VisualStateGroup> </vsm:VisualStateManager.VisualStateGroups> </Grid> </ControlTemplate>
И посоветуйте, пожалуйста, литературу или статьи о xaml применительно к Windows Phone?

Reply With Quote

