I have the follow XAML code:
<Grid ManipulationDelta="Grid_ManipulationDelta" ManipulationMode="TranslateX" Margin="10,134,0,0" HorizontalAlignment="Left" Width="203" Height="120" VerticalAlignment="Top">
<ScrollViewer HorizontalScrollMode="Disabled">
<StackPanel>
<TextBlock Text="Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla " Width="182" TextWrapping="Wrap"/>
<TextBlock Text="Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla " Width="182" TextWrapping="Wrap"/>
<TextBlock Text="Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla " Width="182" TextWrapping="Wrap"/>
<TextBlock Text="Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla " Width="182" TextWrapping="Wrap"/>
<TextBlock Text="Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla Bla " Width="182" TextWrapping="Wrap"/>
</StackPanel>
</ScrollViewer>
</Grid>
I need the scroll viewer for the vertical scrolling only, and I need to capture the TranslateX within the event Grid_ManipulationDela.
It seems that the ScrollViewer Suppresses all the manipulation event from it's parent.
How can I propagate (chaining) the TranslateX from the scroll viewer to the gird in my case?
NB: IsHorizontalScrollChainingEnabled="False|True" does not resolve the problem.
Thank you for your time.
That happens because scrolling is being handled by the compositor thread. You can force it to handle input on the UI thread by setting ManipulationMode of your ScrollViewer to ManipulationMode.System.
Related
In Nativescript-Vue, if I have a ScrollView that is horizontal containing a GridLayout with some elements, let's say simple Labels, how do I make sure that each individual Label does not exceed the ScrollView's width? So that the user will see one full Label (or more, if the Label is short) in the ScrollView and text will never be cut off?
I've tried setting the width of Labels to 100% but it will not work, tried setting the GridLayout width, also does not work.
This is what I have
<template>
<StackLayout height="100%" width="100%" backgroundColor="#add8e6">
<ScrollView id="scroll" orientation="horizontal">
<GridLayout class="m-15" rows="auto" backgroundColor="#90ee90"
columns="auto, auto">
<Label class="h3 m-15" col="0" textWrap="true"
text="Title bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 1"></Label>
<Label class="h3 m-15" col="1"
text="Title bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 2"></Label>
</GridLayout>
</ScrollView>
</StackLayout>
</template>
You have to use FlexboxLayout instead of GridLayout.
The FlexboxLayout will take all available space even if the content is short. If needed, scrollbars are added thanks to ScrollView.
You can then play with justifyContent and alignItems to control alignment, especially when content is short (for instance to center it on the page).
<template>
<Page backgroundColor="#add8e6">
<ScrollView id="scroll" orientation="horizontal">
<FlexboxLayout class="m-15" flexDirection="row" backgroundColor="#90ee90">
<Label class="h3 m-15" textWrap="true"
text="Title bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 1"></Label>
<Label class="h3 m-15"
text="Title bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla 2"></Label>
</FlexboxLayout>
</ScrollView>
</Page>
</template>
I'd like to find Button node within XAML in following PowerShell script. But I can't find it.
[xml]$xaml1 = #'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="400" Width="640">
<Button Content="Button" HorizontalAlignment="Left" Margin="99,20,0,0" VerticalAlignment="Top" Width="60" Height="30"/>
</Window>
'#
$xaml1.SelectNodes("//Button") | ForEach {
$_.Name
}
# No OUTOUT from above code!
When I delete line 3 and 4, it works.
[xml]$xaml2 = #'
<Window
Title="MainWindow" Height="400" Width="640">
<Button Content="Button" HorizontalAlignment="Left" Margin="99,20,0,0" VerticalAlignment="Top" Width="60" Height="30"/>
</Window>
'#
$xaml2.SelectNodes("//Button") | ForEach {
$_.Name
}
# OUTPUT of above code:
Button
How can I find node within XAML with SelectNodes?
I found solution by checking property of each node.The following code works fine.
$xaml.SelectNodes("//*") | ? {$_.LocalName -eq "Button"} | % {
# action for each Button Node
}
The following is sample code using above.
[xml]$xaml = #'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<StackPanel>
<Button x:Name="button0" Content="Button0"/>
<Button x:Name="button1" Content="Button1"/>
<Button x:Name="button2" Content="Button2"/>
<Button x:Name="button3" Content="Button3"/>
<Button x:Name="button4" Content="Button4"/>
<Button x:Name="button5" Content="Button5"/>
<ScrollViewer x:Name="scrollViewer" Height="150">
<TextBlock x:Name="msg" TextWrapping="Wrap"/>
</ScrollViewer>
</StackPanel>
</Window>
'#
$reader = New-Object System.Xml.XmlNodeReader $xaml
$frm = [System.Windows.Markup.XamlReader]::Load($reader)
$scrollViewer = $frm.FindName("scrollViewer")
$msg = $frm.FindName("msg")
$xaml.SelectNodes("//*") | ? {$_.LocalName -eq "Button"} | % {
$button = $frm.FindName($_.Name)
$button.add_Click({
$msg.Inlines.add($this.Content + " pushed`n")
$scrollViewer.ScrollToBottom()
})
}
$result = $frm.ShowDialog()
I'm sorry the followings are code:
[xml]$xaml1 = #'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="MainWindow" Height="400" Width="640">
<Button Content="Button" HorizontalAlignment="Left" Margin="99,20,0,0" VerticalAlignment="Top" Width="60" Height="30"/>
</Window>
'#
[System.Xml.XmlNamespaceManager] $nsmgr = $xaml1.NameTable;
$nsmgr.AddNamespace($null, 'http://schemas.microsoft.com/winfx/2006/xaml/presentation');
$xaml1.SelectSingleNode("//Button", $nsmgr)
Try this:
$xaml1.Window.Button
$xaml.SelectNodes("//*[#Name]") | ForEach-Object {Set-Variable -Name ($.Name) -Value $Form.FindName($.Name)}
Now you have the Controls as Variable...
if the Name of a Button is "button" you have a variable $button in Powershell.
add a click like this then...
$button.add_click({write-host "clicked!!"})
I have a text in my resource dictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="ResourceDictionaryName" Localization.Comments="$Content(DoNotLocalize)">Loc-en-EN</system:String>
<!--MainControl.xaml-->
<system:String x:Key="PersonalEmail">Please enter your email./system:String></ResourceDictionary>
and I bind it to xaml this way:
<TextBlock Text="{DynamicResource PersonalEmail}" Style="{DynamicResource TextBlockStyle}"/>
Is it possible to create style or converter, to show, for example, Please bold, and rest of the text as normal?
String itself does not support rich text format, you can use a Span to show the text.
<TextBlock>
<Span>
<Bold>Please</Bold> enter your email.
</Span>
</TextBlock>
And you can put almost anything into a ResourceDictionary and give it a key, and reference it using that key.
<Window.Resources>
<Span x:Key="PersonalEmail">
<Bold>Please</Bold> enter your email.
</Span>
</Window.Resources>
<Grid>
<TextBlock>
<StaticResource ResourceKey="PersonalEmail" />
</TextBlock>
</Grid>
I could not find in Windows.UI.Xaml.Controls classes a property for a button to make its text move to the next line. For example for a TextBox I can do TextWrapping="Wrap" but what should we do for a button?
Try this
<Button Width="50" Height="50">
<TextBlock Text="Lengthy Data...." TextWrapping="Wrap" />
</Button>
I've got a "popup" context menu on a list box, and there are two behaviors that would seem "out-of-the-box" but I am having a tough time getting the XAML ContextMenu to behave the way I would expect...
One is that, when I pick a sub-menu (e.g. "One" or "Two"), the initial menu continues to stay open (e.g. "Menu" does not go away once I've made a selection).
Second is that the menu margins seem odd. Left justifying Horizontally does not seem to make the main menu (e.g. "Menu") left justify... I can work around this by tweaking the margin - but thats painful for dynamic text..
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<StackPanel>
<ListView>
<ListView.ContextMenu>
<!-- StaysOpen="False" -->
<ContextMenu>
<!-- Background="Transparent" Margin="-8,0,-8,0" -->
<Menu>
<!-- StaysOpenOnClick="False" -->
<MenuItem Header="Menu">
<MenuItem Header="One" />
<MenuItem Header="Two" />
</MenuItem>
</Menu>
</ContextMenu>
</ListView.ContextMenu>
<ListViewItem Content="Red" />
<ListViewItem Content="Orange" />
<ListViewItem Content="Black" />
<ListViewItem Content="Blue" />
<ListViewItem Content="Green" />
</ListView>
</StackPanel>
</Page>
Any thoughts on how to make the Main menu of this popup behave?
Thanks in advance,
T
Try this:
<ContextMenu>
<MenuItem Header="Menu">
<MenuItem Header="One" />
<MenuItem Header="Two" />
</MenuItem>
</ContextMenu>
you are not supposed to have a menu inside a context menu.
you should put menuitem directly.