I have multiple spans within a label. Some spans have a tapped event, and some don't. If two spans with a tapped event wrap to the same line, tapping on the last span will trigger both of the tapped events. If the two spans don't wrap and are on separate lines, it works fine.
<Label VerticalOptions="Start"
HorizontalTextAlignment="Center"
FontSize="Micro"
Margin="70,0,70,0"
LineBreakMode="CharacterWrap">
<Label.FormattedText>
<FormattedString>
<Span Text="This text cannot be tapped. " ></Span>
<Span Text="This text can " TextDecorations="Underline">
<Span.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTextOneTapped"/>
</Span.GestureRecognizers>
</Span>
<Span Text="and "></Span>
<Span Text="this text can also be tapped" TextDecorations="Underline">
<Span.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTextTwoTapped"/>
</Span.GestureRecognizers>
</Span>
<Span Text="."></Span>
</FormattedString>
</Label.FormattedText>
</Label>
private void OnTextOneTapped(object sender, EventArgs e)
{
DisplayAlert("Tap Alert", "You Tapped Text One", "OK");
}
If the screen displays the tapped events text on different lines, it works fine:
This text cannot be tapped. This text can and this text can also be tapped.
If any wrapping occurs where part of the tapped event shares a line with another tapped event, clicking on the latter of the two will cause both tapped events to fire:
This text cannot be tapped. This text can and this text can also be tapped.
Tapping on the text "this text can also be tapped" will fire both OnTextOneTapped and OnTextTwoTapped. Tapping on the text "This text can" will only fire OnTextOneTapped.
Are my tapped event spans too close together (only separated by the word "and")? I only want one tapped event to fire per tap.
I have solution other for you:
Solution: You make a stacklayout contains multiple label, and excute tapped event.
Related
I have been struggling for the past few hours to get a button click to work. The button contains text and an SVG, when clicking on it it opens a popover component.
The popover calculates its position on the element that was clicked upon. This works when clicking on the button itself, but when clicking on the SVG inside of the button, the dimensions/offsets from the SVG are used to calculate popover position instead.
What am I looking for: a way to bubble the click on the SVG to the button, then using the event object from the button click to calculate the popover position.
How my button with events looks like right now:
<button type="button"
#click="popButtonClicked">
Go do magical stuff
<svg path="" />
</button>
I have tried playing with #click.modifiers on both the button and SVG, but to no avail.. Hope someone has the answer for me! :)
You can get the button's reference by passing the $event as a parameter to your function, and then accessing the .currentTarget of that reference:
<button type="button"
#click="popButtonClicked($event)">
Go do magical stuff
<svg path="" />
</button>
And then in your function:
popButtonClicked (event) {
console.log(event.currentTarget)
}
Working codepen: https://codepen.io/anon/pen/gdBBdz
When creating a default C++ xaml blank app for UWP from visual studio add the following code in the xaml page.
<ScrollViewer>
<StackPanel>
<TextBox Height="20"></TextBox>
<TextBox Height="800"></TextBox>
<Button Content="Enabled" IsEnabled="True"></Button>
<Button Content="Disabled" IsEnabled="False"></Button>
</StackPanel>
</ScrollViewer>
If I put the focus on the Enabled button and after that I press the disabled button the focus shifts to the first TextBox.
I found a workaround, to add a 0 dimension focusable element as the first element of the stack panel. <Button Width="0" Height="0"></Button>
But this will affect the other children. ( The id will be changed by 1 )
Do you know a more elegant way of keeping the focus on the previous element after pressing a disabled button in a panel from a scollviewer?
The behavior is not present if the stackpanel is not in a scrollviewer.
You can programmatically change the app's focus in the ScrollViewer's Tapped event.
In the xaml:
<ScrollViewer Tapped="ScrollViewer_Tapped">
<StackPanel>
<TextBox Height="20"></TextBox>
<TextBox Height="200"></TextBox>
<Button Content="Enabled" x:Name="EnableButton"></Button>
<Button Content="Disabled" IsEnabled="False"></Button>
</StackPanel>
</ScrollViewer>
In the xaml.cpp, handle the ScrollViewer_Tapped event to make the EnableButton get focus.
void CApp::MainPage::ScrollViewer_Tapped(Platform::Object^ sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e)
{
EnableButton->Focus(Windows::UI::Xaml::FocusState::Programmatic);
}
If you have any other Controls who can get focus, you should also handle their similar event to assign the focus.
Found a solution. On PointerPressed get the current focused element as an UIElement^ and capture the pointer
I have a UserControl that controls scrolling of a ListView, kind of like a custom ScrollBar. The issue occurs when:
An item in the ListView has keyboard focus (i.e. the focus visual is
set on the item)
I grab and drag my control
Make the release outside of the control (e.g. over the ListView)
Result is that the ListView item loses its focus in the same way it would if I had just clicked outside of the ListView. This is not the way a regular ScrollBar behaves and in fact if I have a Button in my control, click that and make the release outside of the control the Button somehow blocks the release event and the ListView item keeps its focus.
I've tried setting CapturePointer in the PointerPressed handler of my UserControl, but the item still loses focus (although the PointerReleased handler of the ListView isn't called).
UserControl:
<Grid x:Name="RootGrid" Background="AliceBlue">
<Button IsTabStop="False">OKOK</Button>
</Grid>
MainPage:
<Grid x:Name="RootGrid" Background="Gray">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ListView>
<TextBlock Text="ListViewItem 1" />
<TextBlock Text="ListViewItem 2" />
<TextBlock Text="ListViewItem 3" />
</ListView>
<local:MyControl Grid.Row="1" />
</Grid>
So in the above example:
Press tab so that an item in the ListView is marked with the black focus rectangle
Press the blue area with the mouse, drag to gray area and release
Notice how the black focus rectangle disappears. Repeat the steps above but press the Button instead of pressing the blue area and notice how the black focus rectangle doesn't disappear. I want the same behavior when dragging from the blue area as when dragging from the Button.
Code:
<ScrollView>
<StackLayout VerticalOptions="Start">
<local:myListPicker x:Name="LP"></local:myListPicker>
<Label Text="Push me"></Label>
<Label Text="DOWN"></Label>
</StackLayout>
</ScrollView>
I added four Items to the ListPicker, when I tap on it, it opens, but only the first one can be seen, since it does not "push away" the two labels under it.
It looks like the ListPicker is "behind" the two labels, why is that and how to fix?
Additinol Info:
ExpansionMode equals ExpansionMode.ExpansionAllowed.
With 5 or more Items in the List it gets fullscreen (which is totally OK)
Im new to NS and I have a project. I want a Button floating inside a ScrollView.
<ScrollView>
<StackLayout orientation="vertical">
<AbsoluteLayout >
<Button top="0" left="0" right="0" text="Test" style="font-size: 10; margin:5; " />
</AbsoluteLayout>
<Label text="Trending Now: " cssClass="trending-label" />
<Repeater items="{{ categories }}">
<Repeater.itemTemplate>
.
.
.
</Repeater.itemTemplate>
</Repeater>
</StackLayout>
</ScrollView>
But its not working. The Button is also scrolling. I want the Button to be floating on ScrollView. Thank you.
The reason why the button is scrolling together with the other items is that everything is situated in a ScrollView. In order to have only the Label and the Repeater scrolling, the Button should be placed outside of it.
Another thing I have noticed is that on the Button, simultaneously are applied left and right alignment, which might cause a problem.
I made a possible implementation of the float button, which you can check here.