Button with image and stackpanel with text misses the mouse click event in Windows Store App? - xaml

In my Windows Store App I use a button which has a star shape with some text. I use the following XAML code for the button:
<Button Name="goButton" BorderThickness="0" FontWeight="Bold" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-91,33,0" FontSize="25" IsEnabled="True" Click="goButton_Click" >
<Grid Width="227" Height="222">
<Image Source="Assets/redstar.png" />
<StackPanel Orientation="Vertical" Margin="77">
<TextBlock TextAlignment="Center" Text="Tag"></TextBlock>
<TextBlock TextAlignment="Center" Text="ist um!"></TextBlock>
</StackPanel>
</Grid>
</Button>
This is what is the button looks like:
Unfortunately it often happens that clicks in the area of the star are not recognized, e.g. the event handler is not startet. I suppose that it has something to do with the image, for it works fine if I remove the image from the grid. But this doesn't solve my problem.
Any suggestions?

Don't see anything wrong off the top. You could try a couple of things:
Instead of click, try the Tapped event for the button.
Try tapped on the container Grid.
Get rid of the Grid & put all button content in a StackPanel & then try tapped/clicked on it.
Go with patterns like MVVM & associate your button with a Command.
Hope these help!

Related

XAML: MouseLeftButtonUp only fires when clicking text, not whitespace

I have a list box (in Silverlight) that uses a DataTemplate for the ItemTemplate. The DataTemplate is defined like this:
<DataTemplate>
<StackPanel Orientation="Horizontal"
MouseLeftButtonUp="RoleStackPanel_MouseLeftButtonUp"
Tag="{Binding}">
<TextBlock Name="roleItem"
Text="{Binding Path=DisplayValue, Mode=TwoWay}"/>
</StackPanel>
</DataTemplate>
I have found that my event RoleStackPanel_MouseLeftButtonUp only fires if any text displayed in the TextBlock is clicked. If the user clicks any whitespace in the item to the right of the text, the event does not fire. So lets say the control is 300px wide but only has the word "Admin" in the item, you MUST click "Admin" and not to the empty whitespace to the right.
How can I make it so the events fires wherever I click in the item, on text or whitespace?
So a couple quick considerations to get you sorted.
a.) The area of your panel does not have HitTestVisibility by default. This is by design and intentional. To get your event to fire for the parent simply add the property of IsHitTestVisible="True" or provide a Brush for the panel via Background="Transparent" to it to invoke HitTestVisibility.
b.) A StackPanel will only consume the space required by its children. If you wish to provide a large area for a user to hit like you describe than swap the StackPanel for Grid which should consume whatever space is made available by its parent. Same rules of HitTestVisibility apply.
<DataTemplate>
<Grid IsHitTestVisible="True"
MouseLeftButtonUp="RoleStackPanel_MouseLeftButtonUp"
Tag="{Binding}">
<TextBlock Name="roleItem"
Text="{Binding Path=DisplayValue, Mode=TwoWay}" />
</Grid>
</DataTemplate>
Hope this helps, cheers!

Windows 8 Store App Sliding Panel

I am working on a Windows 8 Store App. I want to use sliding panel for my application such as facebook mobile application leftside menu or rightside friends list. What am i want to do ? When i click to button panel should open left 0 to right side about 300px but i didn't find any solution for this. Can you help me for this ? Thx inadvance.
I SOLVED
Actually, I don't want to work with scrollview i want to show a setting pane. I solved my problem with using settingflyout. So, you can use basicly in your project. Add new item >> add settingflyout. But thx for your answer.
<ScrollViewer
x:Name="HorizontalScrollViewer"
VerticalScrollBarVisibility="Auto"
VerticalScrollMode="Disabled"
ZoomMode="Disabled"
HorizontalScrollBarVisibility="Auto"
HorizontalScrollMode="Auto"
HorizontalSnapPointsAlignment="Near"
HorizontalSnapPointsType="Mandatory">
<StackPanel
Orientation="Horizontal">
<Grid
x:Name="LeftPanel">
...
</Grid>
<Grid
x:Name="CenterPanel">
<ListView .../>
</Grid>
<Grid
x:Name="RightPanel">
...
</Grid>
</StackPanel>
</ScrollViewer>

ScrollViewer Issue with StackPanel in Windows Phone 8

I put StackPanel into ScrollViewr, When scrolling to last item it returns back to its old position.
<ScrollViewer Margin="0,0,0,20">
<StackPanel>
//Textblocks and Textboxes ...
</StackPanel>
</ScrollViewer>
After search i found that:
ItemsControl, VirtualizingStackPanel and ScrollViewer height
I changed my code to:
<StackPanel>
//Textblocks and Textboxes ...
</StackPanel>
<ScrollViewer>
<VirtualizingStackPanel />
</ScrollViewer>
I can't set CanContentScroll="True" as i can't find it.
Also make exception:
System.InvalidOperationException: A VirtualizingPanel is not nested in an ItemsControl. VirtualizingPanel must be nested in ItemsControl to get and show items.
What must i do, to enable scrolling without returning back to its old position?
Regards,
After search again ...
I found this Post which solve the problem of Scrolling return to old position when open keyboard.
Scrolling page with keyboard shown
code after updates:
<ScrollViewer Height="500" VerticalAlignment="Top">
<StackPanel Height="700">
//Textblocks and Textboxes ...
</StackPanel>
</ScrollViewer>

Windows phone 8 Button style is transparent

My button looks like a text field instead of a button. Here's a screenshot:
Here's the code:
<Button FontWeight="Bold" Click="setWallpaper" Foreground="black" FontSize="35"
Margin="62,560,127,48" >Set Lockscreen</Button>
How do I fix it and make it look like a good old button?
Looks like the problem is that you have an image as your background and the button is transparent so it is showing the image. Just change your button background to White and it should fix it
<Button FontWeight="Bold" Click="setWallpaper" Foreground="Black" FontSize="35" Background="White" Margin="62,560,127,48" >Set Lockscreen</Button>

Xaml, How to bind a list of buttons over an image in different coordination

For a windows 8 Apps, i need to put a list of buttons over an image. Each button has CoordinateX and CoordinateY properties. I use a gridView to bind to the list of buttons.
I need to have the result as below:
Here is my code:
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" >
<Canvas>
<Image Source="ms-appx:///Assets/red.png" Stretch="None" ></Image>
<GridView ItemsSource="{Binding Buttons}"
SelectionMode="None" IsSwipeEnabled="false" IsItemClickEnabled="True" ItemClick="Button" Padding="0">
<GridView.ItemTemplate>
<DataTemplate>
<Button Width="194" Height="51" Background="Gray" Canvas.Left="{Binding CoordinateX}" Canvas.Top="{Binding CoordinateY}"></Button>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</Canvas>
</Grid>
But this is what i get after running the app:
Ites Likely that at runtime before the X and Y co-ordinates can be set for the items within the GridView, the GridView itself has its properties applied.
Since
1) the GridView is intended to be used for oganization control
and
2) you havent forced the Grid to fill the view space
what you're left with is a GridView that acts as it wishes and limits the ability of its items to conform to your style, should the style attempt to force the items collection to live outside the bounds of the control.
You could try to set the GridView's Horizontal Alignment property but even if it happens to work, its probably a better bet to use a less organized content control like the more basic ItemsPresenter.
Which ever control you end up using... make sure to check for /set the HorizontalContentAlignment & VerticalContentAlignment properties if they exist.