How can I create a tab control with Arabic content horizontally? - wpf

I'm trying to create a tab control in WPF with Arabic content vertically but unfortunately it shown vertically not in the horizontal orientation.
It works only with English content ( headers )
Code :
<TabControl Width="100" Height="80" x:Name="tab" ItemsSource="{Binding Items}">
<TabControl.ContentTemplate>
<DataTemplate>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
how can I fix that?

Its not issue of arabic language, but lenght of the words.
Remove
Width="100"
If you dont want it to be spread to full width, then set HorizontalAlignment like:
HorizontalAlignment ="Left"
Or
HorizontalAlignment ="Center"

Related

How to prevent the TreeView's DataTemplate from causing the control to expand horizontally?

Very new to WPF.
<TreeView Grid.Column="0" x:Name="DataTree" MinWidth="175" BorderThickness="0">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type self:DispatchTreeTerritoryItem}" ItemsSource="{Binding ClientLocations}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type self:DispatchTreeClientLocationItem}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ClientName,StringFormat='({0}) '}" />
<TextBlock Text="{Binding Address}" />
</StackPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
The data in the DispatchTreeClientlocationItem properties (ClientName and Address), do not fit within the width of the treeview. So when the items are created the treeview control expands itsself horizontally to allow all the tree node's text to be visible.
This is not desired behavior. I would like it to behave like WinForms TreeView, where the text is just truncated at the edge of the control. Is that possible in WPF? And how?
UPDATE
Following #Funk's comment and the suggestion in the linked question my TreeView XAML now looks like:
<TreeView x:Name="DataTree" Grid.Column="0" MinWidth="175" BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
I've observed no change in the behavior. When node text is too long to fit within the horizontal confines of the TreeView, the TreeView expands horizontally to display all the text.
Here's a couple screenshots to illustrate the problem. When expanding a territory node, the child node's contents cause the TreeView to expand horizontally.
if TreeView is located in a Grid and ColumnDefinition has Width="Auto", expanding is an expected behavior.
Try set MaxWidth (on ColumnDefinition or on TreeView), or proportional width * / fixed width (on ColumnDefinition)
Grid rows (RowDefinition) have similar behavior when their Height is set to Auto

WPF: Textblock as item in ComboBox: how to center the text of Textblock vertically?

I use WPF 4.5, Caliburn Micro 2, VS2013. I use TextBlock as item in ComboBox.
The height of ComboBox is 80.
The height of TextBlock is 50.
The font size of text inside the TextBlock is standard.
My following sample xaml code works but it shows the text not vertically centered in TextBlock. How to make the text vertically centered with/without changing the height of TextBlock to Auto? Thank you in advance.
<ComboBox Width="150"
Height="80"
VerticalContentAlignment="Center"
ItemsSource="{Binding Path=Locations}"
SelectedIndex="0"
SelectedItem="{Binding Path=SelectedLocation,
Mode=OneWayToSource}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Height="50"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="Aquamarine"
Text="{Binding Path=Address}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
And here is the screenshot:
A TextBlock should not have a height but its container should instead. If you want to set the background color for your TextBlock then wrap your TextBlock in a Border or a Grid and set the height on them instead.
Like
<Grid Height="50>
<TextBlock VerticalAlignment="Center" Text....../>
</Grid>
Text-Align="center"
or you could use a margin on each of the sides.

WinRTXamlToolkit TreeView item stretch horizontally

I'm trying to make tree view item stretch horizontally
Here is my original outcome
But what I want is this
here is my XAML code
<Grid x:Name="AgendaGrid" Grid.Row="1">
<Controls:TreeView ItemsSource="{Binding TreeItems}" Style="{StaticResource TouchTreeViewStyle}">
<Controls:TreeView.ItemTemplate>
<DataTemplate>
<data:DataTemplateExtensions.Hierarchy>
<data:HierarchicalDataTemplate ItemsSource="{Binding Children}" />
</data:DataTemplateExtensions.Hierarchy>
<Grid>
<Button Visibility="{Binding IsHeading}" Padding="0" Content="{Binding Name}" />
</Grid>
</DataTemplate>
</Controls:TreeView.ItemTemplate>
</Controls:TreeView>
</Grid>
The simple way to achieve what you want would be to use the HorizontalContentAlignment property:
<TreeView ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" />
Unfortunately, that won't work with a TreeViewItem. That is because the ControlTemplate of the TreeViewItem features a hard coded top level Grid that has the wrong RowDefinitions set up for this requirement. Therefore, the way to fulfil your requirement is to alter the default ControlTemplate, which you can find in the TreeView Styles and Templates page on MSDN.
Rather than repeat the whole story again here, I'd rather direct you to a solution on the Horizontal stretch on TreeViewItems page of LeeCampbell's Blog. That describes the problem in a little more detail and suggests the solution of a simple tweak to the ControlTemplate.

How do you make a vertically scrolling scrollviewer inside a tabControl?

I want to make it so that my TabControl is vertically scrollable, but I can't seem to do it. The following sample acts as though there was no scrollviewer at all. I even tried putting the TabControl inside the scrollviewer, or putting it all in a grid and constraining the height of the grid, but nothing works.
<DataTemplate x:Key="tabControlTemplate">
<TabControl ItemsSource="{Binding guiItems}" DisplayMemberPath="Title" Height="Auto" Template="{StaticResource mainTabControlTemplateEx}">
<TabControl.ContentTemplate>
<DataTemplate>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<StackPanel Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl ItemsSource="{Binding guiItems }" ItemTemplateSelector="{DynamicResource templateSelector}"/>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
</DataTemplate>
The actual problem is not clear from the question.
You are not getting to see scrollviewer and the content inside is clipped? PLease confirm if that is the case.
If the problem is you are getting to see entire content taking up all the available space, and you would like to control that using scroll viewer, then you would need to set 'MaxHeight' property on Scroll Viewer. This would limit the height of your DataTemplate and would make verticall scroll bar visible if the inner content goes beyond the MaxHeight.
Hope that helps.

center align contents of a listbox in silverlight

I have a list box which is of a certain fixed width. The number of items in the listbox varies. Is there a way to center the contents of the list box? The "Content Presenter" of the ListBoxItem ,centers each item inside its Template instead of centering it with respect to the entire listbox width.
Sorry about not replying earlier. The issue was with the width of the ItemsPanelTemplate which I was using in my Listbox. Earlier Width was set to 925. Changing this Width to MaxWidth worked. The code:
<ItemsPanelTemplate x:Key="ItemsPanelKey">
<Contact:AnimatedWrapPanel HorizontalAlignment="Center" MaxWidth="925">
<Contact:AnimatedWrapPanel.Interpolation>
<interpolate:BackInterpolation Amplitude=".5" Suppression=".2" EdgeBehavior="5"/>
</Contact:AnimatedWrapPanel.Interpolation>
</Contact:AnimatedWrapPanel>
</ItemsPanelTemplate>
Not sure, but sounds like what you want is a custom item template that centers each item. If I'm right, the only tricky thing is that the template has to be the same fixed width as the listbox. So if your listbox contains some object Foo and Foo.Text is a simple text property to be displayed, you could do it like so in Xaml:
<ListBox x:Name="TheListBox" Width="300">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="300">
<TextBlock Text="{Binding Text}" HorizontalAlignment="Center" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
and the code behind contains something like:
List<Foo> ListOfFoo = new List<Foo>();
ListOfFoo.Add(new Foo(){Text="Something"});
ListOfFoo.Add(new Foo(){Text="Something Else"});
ListOfFoo.Add(new Foo(){Text="Something Completely Different"});
TheListBox.ItemsSource = ListOfFoo;
If it's more complex or you can't make it work, post some code and we'll go from there.

Resources