Template10 FocusAction to move focus after Enter key? - winrt-xaml

Is it possible to use FocusAction to move focus to another control from a KeyBehavior? If so, an example would be helpful. TIA

Fascinating.
This is what does NOT work:
<TextBox x:Name="T1">
<Interactivity:Interaction.Behaviors>
<b:KeyBehavior Key="Enter">
<b:FocusAction TargetObject="{Binding ElementName=T2}" />
</b:KeyBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
<TextBox x:Name="T2" />
But I love the idea and I will add it to the behavior soon.
In the meanwhile, there is no declarative way to do it without a custom something you create. BTW, I tried this (also does NOT work):
<TextBox x:Name="T1">
<Interactivity:Interaction.Behaviors>
<b:KeyBehavior Key="Enter">
<Core:CallMethodAction MethodName="Focus" TargetObject="{Binding ElementName=T2}" />
</b:KeyBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
<TextBox x:Name="T2" />
Does not work because Focus has parameters and the behavior does not support passing parameters. Though I wish it would.
Great idea though. Sort of like forcing TAB, huh? Cool.
Jerry

Related

Xamarin ListView Issue

I am beginer on Xamarin. What did I do wrong here. I am trying to add Conext Menu to ListView and compiler is not happy with this.
<ListView x:Name="VehicleList">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
ImageSource="152x152#1x.png"
Text="{Binding Title}"
Detail="{Binding SubTitle}"
TextColor="#f35e20"
DetailColor="#503026" />
<!-- adding this caused error
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
Text="Archive"
IsDestructive="True" />
</ViewCell.ContextActions>
</ViewCell>
-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You are defining two viewcells in one data template. this is not possible!
You should create a DataTemplateSelector and declare the ViewCells in separate classes. Then you can make the selector choose a viewcell based on the logic implemented in the DataTemplateSelector. The xamarin documentation has a nice explanation: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

Cancel WinRT ComboBox infinte scroll effect

How to cancel the infinite scroll effect on the ComboBox in WinRT. I tried a lot of solutions but no one seems working.
PS: I got this issue only in the touch mode !
Thank you,
You need to change the ItemsPanelTemplate to StackPanel.
<ComboBox Width="200" Height="50">
<ComboBoxItem Content="Test"/>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>

How to clone UIElement in Silverlight

Can anybody tell me how to clone UIElement in SILVERLIGHT ?. I dug a lot in the google but I'm not able to find relevant solution, everywhere I'm just getting solution to clone UIElement in WPF, however same is not applicable in the Silverlight.
I need to add the a UIElement in the same grid's next rows on click of a + button eachtime.
Plz help..any answer will be appreciable
Thanks
GK
There is no facility to do that.
In your scenario you can use an ItemsControl (directly or as a ListBox, for example) and provide your to-be-duplicated piece of UI as a datatemplate:
<ItemsControl ItemsSource="{Binding MyData}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding LabelText}" />
</Grid>
<DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This is the most typical way of doing it, but you will need to know about databinding to do it.
There is also the possibility of factoring out your to-be-duplicated piece of UI in a UserControl and add that programmatically multiple times.

'ToolTip' cannot have a logical or visual parent

I have the following problem. I keep getting 'ToolTip' cannot have a logical or visual parent error when i try to style tooltip for the toggle button. What went wrong? When i take out the tooltip control under ToggleButton.ToolTip it works !
<ToggleButton x:Name="toggle" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" Margin="0,4,0,0" VerticalAlignment="Top" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
</ToggleButton>
If you write code like this using property element syntax, you call already the constructor of the ToolTip class.
<ToggleButton.ToolTip>
<TextBlock></TextBlock>
</ToggleButton.ToolTip>
There is no need to instantiate another ToolTip inside like this...
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
Besides, on my system (using .NET 4.5) there is no error.
It seems that WPF can handle both versions meanwhile as intended by the developer.

WPF: Custom control that binds its content to a label

I want to write a custom control that's used like this:
<HorizontalTick>Some string</HorizontalTick>
It should render like this:
-- Some string -------------------------------------------
Here's my code:
<UserControl x:Class="WeatherDownloadDisplay.View.HorizontalTick"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignWidth="348"
Name="controlRoot">
<DockPanel LastChildFill="True">
<UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1" Width="10"/>
<Label Content="???" />
<UserControl VerticalAlignment="Center" BorderBrush="Black" BorderThickness="1"/>
</DockPanel>
</UserControl>
It works except for the label binding. Can someone help me fill in the question marks? I thought about using a ContentPresenter but it seems like an inline binding would be best.
-Neal
The binding would be:
<Label Content="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content}" />
However, reconsider using a ContentPresenter to be able to show any content directly rather than adding a label that will use its own ContentPresenter to show it.
That being said, you could also replace your whole control by a simple ContentControl with a ContentTemplate showing the lines and the inner content.

Resources