michielpost.nl

Simple ImageButton for Windows 8 / WinRT

30-07-2012

If you want to have a simple imagebutton in your Windows 8 app (XAML) you can use this style. All it does is show the image and a nice pressed style when the image is touched. It uses the PointerDownThemeAnimation included with the WinRT framework.

If you're looking for a more complex variant, with multiple images to show a pressed state, have a look at http://winrtxamltoolkit.codeplex.com/

Include this in your resources (App.xaml):

<!--Image Button with simple pressed state -->
            <Style x:Key="ImageButtonStyle" TargetType="Button">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Grid>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="PointerOver">
                                        </VisualState>
                                        <VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <PointerDownThemeAnimation TargetName="Border"/>
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Disabled">
                                        </VisualState>
                                    </VisualStateGroup>
                                    <VisualStateGroup x:Name="FocusStates">
                                        <VisualState x:Name="Focused">
                                        </VisualState>
                                        <VisualState x:Name="Unfocused" />
                                        <VisualState x:Name="PointerFocused" />
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="Border">
                                    <ContentPresenter x:Name="ContentPresenter"
                                              Content="{TemplateBinding Content}"
                                              ContentTransitions="{TemplateBinding ContentTransitions}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

Usage:

<Button Style="{StaticResource ImageButtonStyle}">
   <Image Source="image.png" />
</Button>

Comments


Stefan 29-05-2015
How do you put a text over the image?


The abitliy to think like that shows you're an expert 12-11-2015
The abitliy to think like that shows you're an expert


Kudos! What a neat way of thikinng about it. http://oozatsct.com [url=http://bfkjhldsunf.com]bfkjhldsunf[/url] [link=http://iqmcvnu.com]iqmcvnu[/link] 14-11-2015
Kudos! What a neat way of thikinng about it. http://oozatsct.com [url=http://bfkjhldsunf.com]bfkjhldsunf[/url] [link=http://iqmcvnu.com]iqmcvnu[/link]


buy cialis 20-08-2020
Best Buy Discount Clobetasol Saturday Delivery Store Price Baton Rouge Weroummire https://biracialism.com/ - buy cialis cheap Riferaro Pastilla Cialis Scedeply <a href=https://biracialism.com/#>cialis online reviews</a> UnaraEnhaf acheter du viagra


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102& 19-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102& 19-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102& 19-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102& 20-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102& 20-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102& 21-11-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. http://bit.do/fLc9r?h=f98427e4417066ccb723a19f2a6f5102&


???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102& 04-12-2020
???????? ?? ? ????, ????? ???????? ??????, ? ? ????, ????? ???? ????? ????? ?????. https://helloworld.com?h=f98427e4417066ccb723a19f2a6f5102&


Buy legal anabolic steroids https://myfsk.org/community/account/buy-legal-anabolic-steroids/?h=f98427e4417066ccb723a19f2a6f5102& 13-12-2020
Buy legal anabolic steroids https://myfsk.org/community/account/buy-legal-anabolic-steroids/?h=f98427e4417066ccb723a19f2a6f5102&


Buy legal anabolic steroids https://myfsk.org/community/account/buy-legal-anabolic-steroids/?h=f98427e4417066ccb723a19f2a6f5102& 13-12-2020
Buy legal anabolic steroids https://myfsk.org/community/account/buy-legal-anabolic-steroids/?h=f98427e4417066ccb723a19f2a6f5102&


<p><a href="https://f3gxp.page.link/Tbeh"><img src="https://i.ibb.co/rH6Ky7F/best-hookup-sites-fs.jpg"></a></p>?h=f98427e4417066ccb723a19f2a6f5102& 20-12-2020
<p><a href="https://f3gxp.page.link/Tbeh"><img src="https://i.ibb.co/rH6Ky7F/best-hookup-sites-fs.jpg"></a></p>?h=f98427e4417066ccb723a19f2a6f5102&


<p><a href="https://f3gxp.page.link/Tbeh"><img src="https://i.ibb.co/rH6Ky7F/best-hookup-sites-fs.jpg"></a></p>?h=f98427e4417066ccb723a19f2a6f5102& 21-12-2020
<p><a href="https://f3gxp.page.link/Tbeh"><img src="https://i.ibb.co/rH6Ky7F/best-hookup-sites-fs.jpg"></a></p>?h=f98427e4417066ccb723a19f2a6f5102&


TmhWN 10-01-2021
Drug information sheet. Long-Term Effects. <a href="https://viagra4u.top">how to get generic viagra without prescription</a> in Canada. Actual what you want to know about medicine. Read information here. <a href=http://shop.khunjib.com/product/498.html>All news about drugs.</a> <a href=https://www.bestattung-glueck.at/sterbefall.php?id=215&name=Gottfried-Daxb%25C3%25B6ck>Some trends of drug.</a> <a href=https://dienmaysonganh.com/san-pham/may-thai-hanh-toi-quay-tay-inox.html>Best what you want to know about drugs.</a> 144e8b7


New Comment

Name
E-mail (not published)
Comment
Enter the code shown: