I have a Grid in which I have a RichTextBox control for the description text and there is a ToolTip attached with that RichTextBox. Please check the below code-
<Grid Grid.Row="1" >
<controls:RichTextBox Text="{Binding Description, Mode=TwoWay}"
VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" IsEnabled="False" />
<Grid.ToolTip>
<ToolTip>
<TextBlock Text="{Binding Path=Descriptiontext}"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap" />
</ToolTip>
</Grid.ToolTip>
</Grid>
And I wanted to set "ToolTipService.ShowDuration" property for ToolTip. But I am not getting a way, where to attach it.
Can anyone suggest how we can do that.
The ShowDuration property is actually an attached property from the contained TooltipService. You can put it either on the ToolTip itself or the parent Grid. i.e.
<Grid Grid.Row="1" ToolTipService.ShowDuration="5000">
<controls:RichTextBox Text="{Binding Description, Mode=TwoWay}"
VerticalAlignment="Stretch" VerticalContentAlignment="Stretch" IsEnabled="False" />
<Grid.ToolTip>
<ToolTip>
<TextBlock Text="{Binding Path=Descriptiontext}"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap" />
</ToolTip>
</Grid.ToolTip>
</Grid>
Related
I want to move focus from Title Textbox to Textbox in ContentControl in WPF.
But any command doesn't work.
How can I move focus?
<TextBox
Grid.Row="0"
MinWidth="200"
Name="Title"
VerticalContentAlignment="Center"
mahApps:TextBoxHelper.ClearTextButton="True"
mahApps:TextBoxHelper.Watermark="Task Title"
Text="{Binding Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<StackPanel
Grid.Row="1"
Margin="0,5,0,5"
Background="White">
<ContentControl
MinHeight="55"
Margin="5"
Content="{Binding CreateTaskControl}" />
</StackPanel>
you can use Focusable="True" and KeyboardNavigation.TabIndex="1"
And of course if TabIndex you did not use it.
this code Focusable="True" and KeyboardNavigation.TabIndex="1" Useful for places that do not accept the TabIndex element, such as TextBlock
I have ListView and i inserted Slider and TextBlock in the same column:
<DataTemplate x:Key="MyDataTemplate2">
<Grid Margin="-7" >
<Slider Name="sliderColumn"
HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource SliderStyle}" Width="80"/>
<TextBlock Text="{Binding Path=Value, ElementName=sliderColumn, StringFormat={}{0}}" FontSize="11" Foreground="White"
VerticalAlignment="Center" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
And this is the result:
Bu when the Slider value changed it become unreadable:
Any suggestions how to fix it and make sure to display only integer numbers ?
Change your slider Like this by ading these two properties in slider TickFrequency and IsSnapToTickEnabled
<Slider Name="sliderColumn"
HorizontalAlignment="Left" VerticalAlignment="Center" Width="80" TickFrequency="1" IsSnapToTickEnabled="True"/>
I have a Silverlight page that is using MVVM. on the page I have several controls that I need to validate. for dropdowns and text boxes it is not so hard. i.e.
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding EmailAddress, Mode=TwoWay, ValidatesOnNotifyDataErrors=True}">
<i:Interaction.Behaviors>
<behaviors:UpdateOnTextChangedBehavior />
</i:Interaction.Behaviors>
</TextBox>
and I get the nice little red box with my message that I bound in the model.
but I also have a place were I have two check boxes in a stackpanel. I need to make sure one of the boxes is check. and I would like the error message to show up ether next to the stackpanal or the labeltextbox that is the 1st item in the stackpanal.
<StackPanel Grid.Row="6"
Grid.ColumnSpan="2">
<ac:LabelTextBox Content="Business Group(s):" />
<CheckBox HorizontalAlignment="Left"
VerticalAlignment="Center"
IsThreeState="False"
Content="XXX"
IsChecked="{Binding User.HasXXXUserRole, Mode=TwoWay, ValidatesOnExceptions=True}"
Margin="3"
FlowDirection="LeftToRight">
</CheckBox>
<CheckBox HorizontalAlignment="Left"
VerticalAlignment="Center"
IsThreeState="False"
Content="YYY"
IsChecked="{Binding User.HasYYYUserRole, Mode=TwoWay, ValidatesOnExceptions=True}"
Margin="3"
FlowDirection="LeftToRight" />
</StackPanel>
Thanks
Danny
In a datatemplate that I am binding to a viewmodel I have a grid like so:
<Grid>
.
. <!--Row & Col Definitions...-->
.
<TextBlock Text="Some Label" Style="{DynamicResource TextBlockLabelStyle}" />
<TextBlock Grid.Column="1" Text="{Binding SomeValue, Mode=OneWay}"/>
<Border Style="{DynamicResource SeparatorStyle}" />
<TextBlock Grid.Row="1" Text="Some Label" Style="{DynamicResource TextBlockLabelStyle}" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding SomeValue, Mode=OneWay}"/>
<Border Grid.Row="1" Style="{DynamicResource SeparatorStyle}" />
<TextBlock Grid.Row="2" Text="Some Label" Style="{DynamicResource TextBlockLabelStyle}" />
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding SomeValue, Mode=OneWay}"/>
<Border Grid.Row="2" Style="{DynamicResource SeparatorStyle}" />
</Grid>
I thought that adding this repeated pattern (TextBlock for label, TextBlock for value, horizontal rule) was getting tedious and thought it would be best to encapsulate it into a UserControl something like 'GridRow' e.g.:
<UserControl x:Class="GridRow">
<TextBlock Text="{Binding LabelText}" Style="{DynamicResource TextBlockLabelStyle}" />
<TextBlock Grid.Column="1" Text="{Binding ValueText, Mode=OneWay}"/>
<Border Style="{DynamicResource SeparatorStyle}" />
</UserControl>
Then I could just go something like:
<Grid>
<GridRow LabelText="Some Label" ValueText="{Binding SomeValue}"/>
<GridRow Grid.Row="1" LabelText="Some Label2" ValueText="{Binding SomeValue2}"/>
<GridRow Grid.Row="2" LabelText="Some Label3" ValueText="{Binding SomeValue3}"/>
</Grid>
and have the user control bind to LabelText and ValueText properties, perhaps through template binding?
My question is how to do this, and if this is the right way of doing it, or if it is possible to use Styles or datatemplates to do this?
Unfortunately this is something that is not easy to achieve. A Grid layout looks at the Grid.Row and Grid.Column properties of its immediate children in order to create the required layout. Therefore, nesting your UI controls in another Grid will break the layout.
A few options, this blog post fixes the problem, but is complex:
http://www.scottlogic.co.uk/blog/colin/2010/11/using-a-grid-as-the-panel-for-an-itemscontrol/
There is a nice Auto-grid here, I have not used it, but it looks pretty good:
http://whydoidoit.com/2010/10/06/automatic-grid-layout-for-silverlight/
Regards,
Colin E.
I'm having a little trouble in silverlight with a databound ListBox containing databound TextBox elements. The items display correctly in the list and the TextBox is populated correctly but I can't get focus on the TextBox in the list. If I hover over the edges of the TextBox it highlights but it won't let me click into it to edit the text. Any ideas?
My XAML looks like this:
<ListBox x:Name="listImages">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="LayoutRoot" Background="White">
<Image Height="102" HorizontalAlignment="Left" Name="imgThumb" Stretch="UniformToFill" VerticalAlignment="Top" Width="155" Source="{Binding ImageFilename, Converter={StaticResource ImageConverter}}" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="154,25,0,0" Name="txtAltText" VerticalAlignment="Top" Width="239" Text="{Binding Alt}" />
<dataInput:Label Height="19" HorizontalAlignment="Left" Margin="154,6,0,0" Name="lblAltText" VerticalAlignment="Top" Width="239" Content="Alt Text" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I swapped the content for this and it now works, I think it was having an issue with the Grid container:
<ListBox x:Name="listImages">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Height="102" HorizontalAlignment="Left" Name="imgThumb" Stretch="UniformToFill" VerticalAlignment="Top" Width="155" Source="{Binding ImageFilename, Converter={StaticResource ImageConverter}}" Margin="5" />
<StackPanel>
<dataInput:Label Height="19" HorizontalAlignment="Left" Name="lblAltText" VerticalAlignment="Top" Width="239" Content="Alt Text" />
<TextBox Height="23" HorizontalAlignment="Stretch" Name="txtAltText" VerticalAlignment="Top" Text="{Binding Alt}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>