在WP8创建自己的切换按钮? [英] Creating own toggle button in WP8?
问题描述
我需要移植Android应用程序有一个小部件WP8。
I need to port an Android app which has a widget to WP8.
为此,我需要创建我自己的切换按钮(用户控制)。所以,我只是创建了一个名为MyToggleButton按钮的子类,并使用标准的回调来改变图像和按钮上的文字。
For this I need to create my own toggle button (user control). So I just created a subclass of Button called MyToggleButton and use the standard callbacks to change the image and the text of the button.
要赶上点击下来,我用 OnMouseEnter在
,当点击完成后,即moud按钮,我再次使用上升 OnMouseLeave在
To catch the click down I use onMouseEnter
and when the click is finished, ie the moud button goes up again I use onMouseLeave
Wihle这个工作没有问题 - 问题是,当点击了 OnMouseEnter在
似乎有一点延迟调用,按钮可改变以最小的延迟按钮画面相以一个普通按钮(我使用Visual Studio防爆preSS 2012年模拟器,因为我还没有进行测试的真正的手机)
Wihle this works without problems - the issue is that when clicking the onMouseEnter
seems to be called with a little delay and this button changes the ButtonImage with a minimal delay as opposed to a normal button ( I am using Visual Studio Express 2012 with Emulator since I do not yet have a real phone for testing)
而我发现创建用户控制在XAML specifing很多其他的方法,但是我觉得只是用标准方法更简单的方式描述。我只是不知道,这哪里最小延迟从何而来。
WHile I found other ways of creating user controls specifing lots in XAML, however I find the described way of just using the standard methods easier. I am just not sure, where this minimal delay comes from.
推荐答案
下面是一个简单的切换按钮,使用图像。根据复选框
Here is a simplified "Toggle" button using images. based on CheckBox
<Style TargetType="{x:Type CheckBox}" >
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Grid>
<ContentPresenter x:Name="Part_Content" />
<Image Name="image" Source="/WpfApplication4;component/Images/avatar63.jpg" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true" >
<Setter TargetName="image" Property="Source" Value="/WpfApplication4;component/Images/imagesCA7JZMMY.jpg"/>
</Trigger>
<Trigger Property="IsChecked" Value="False" >
<Setter TargetName="image" Property="Source" Value="/WpfApplication4;component/Images/avatar63.jpg"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这篇关于在WP8创建自己的切换按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!