Could someone please asssit with the below items control as I need my Radio buttons to be Horizontal not vertical
<ItemsControl Name="rbQuestionAnswer" ItemsSource="{Binding Answers, Mode=TwoWay}" IsEnabled="{Binding IsEnabled, Mode=OneWay}" >
<ItemsControl.ItemTemplate >
<DataTemplate >
<RadioButton GroupName="{Binding SurveyLineID}"
Content="{Binding Answer}"
Tag="{Binding AnswerId}"
Style="{StaticResource RadioButtonStyle}"
IsChecked="{Binding IsSelected, Mode=OneWay}"
Checked="RadioButton_Checked"
Visibility="{Binding Path=IsRadio,Converter={StaticResource BoolConverter}}" >
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I think you can use <StackPanel/> to do this. Try the following code.
<ItemsControl ItemsSource="{Binding Options}">
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="{Binding AnswerId}" Content="{Binding Option}" IsChecked="{Binding IsSelected, Mode=OneWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Modify this code to suit your requirements. Hope, it may help you!
Needed to add the below within the Items control:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Related
I have button and under him is text and these buttons are next to each other but are served under him. This is my code:
UserView.xaml:
<WrapPanel Orientation="Horizontal" HorizontalAlignment = "Left">
<ItemsControl ItemsSource = "{Binding Path = Users}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation = "Vertical">
<Button Style="{StaticResource UserButton}" Content="{Binding Name}"></Button>
<Rectangle Style="{StaticResource UserButtonStatus}"
Fill="{Binding Color}" ToolTip="{Binding Tooltip}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</WrapPanel>
MainWindow.xaml:
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Vertical">
<TextBlock Style="{StaticResource Title}">Users</TextBlock>
<view:UserView x:Name="UserView">
<view:UserView.DataContext>
<Binding Path="UserViewModel" Source="{StaticResource ServiceLocator}"/>
</view:UserView.DataContext>
</view:UserView>
</StackPanel>
Required:
Actual (wrong):
You need to overwrite the items controls panel
items control will display each item underneath each other by default.
here is the code to add make sure its inside your items control tab just like you have done with the item template:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
So your userview.xaml will look like this:
<ItemsControl ItemsSource = "{Binding Path = Users}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation = "Vertical">
<Button Style="{StaticResource UserButton}" Content="{Binding Name}"></Button>
<Rectangle Style="{StaticResource UserButtonStatus}" Fill="{Binding Color}" ToolTip="{Binding Tooltip}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
say its a listview bound to a collection
i fix the listview width to 100
the itemtemplate is some thing like below
<DataTemplate> <Border>
<TextBlock Foreground="{Binding Path=Color}"
Text="{Binding Path=Name}"
TextTrimming="CharacterEllipsis"/>
</Border> </DataTemplate>
i want to be able to
maximum allowed is 3 how do i make the text box trim to a uniformresize itself to a proper size giving space to other textboxes
i don't wanto have c# code written is it possible to achieve using only XAML ?
try this
<ListView Width="100">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Width="100" Columns="3"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Border>
<TextBlock Foreground="{Binding Path=Color}" Text="{Binding Path=Name}" TextTrimming="CharacterEllipsis"/>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You can change ItemsPanel to UniformGrid which will split available space evenly between your items. Here's an ItemsControl example
<ItemsControl ItemsSource="{Binding Path=Items}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border>
<TextBlock
Foreground="{Binding Path=Color}"
Text="{Binding Path=Name}"
TextTrimming="CharacterEllipsis"/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I am trying to horizontally align items in a listbox(items are checkbox items). How can i use a wrap panel with datatemplate?
<ListBox Name="Horizontal" ItemsSource="{Binding Solution}" scrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListBox.ItemTemplate >
<DataTemplate >
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Margin="5 5 0 0"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I think you want the ItemsPanel property:
<ListBox Name="Horizontal" ItemsSource="{Binding Solution}" scrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" IsChecked="{Binding IsChecked}" Margin="5 5 0 0"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I have a User Control in a ListBox and when I use the tab key to focus I'd like to get the focus on the TextBox in my Control instead of the Custom Control. How can I do it?
I simplified the code because In my control I have other UI Elements.
User Control Code:
<Grid>
<TextBox Name="txtFreeTextDescription" Style="{StaticResource TextBoxStyleLargeDynamic}" Text="{Binding Description, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
</Grid>
ListBox Code:
<ListBox Name="lsbItems" DataContext="{Binding}" KeyboardNavigation.TabNavigation="Local">
<ListBox.ItemTemplate>
<DataTemplate>
<local:SectionDynamicItem x:Name="ucSectionDynamicItem" Description="{Binding SectionItem.Description}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This works for me....
<ListBox ItemsSource="{Binding EmployeeList}"
KeyboardNavigation.TabNavigation="Continue">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Focusable" Value="False"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="5" Focusable="False">
<TextBox Text="{Binding Name}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
Check below link.
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/98d8423c-9719-4291-94e2-c5bf3d80cd46/
Thanks
Rajnikant
I am trying to bind a List of objects to an ItemsControl. The object has only two properties: Movie (a string) and Actors (an array of string). I can get the binding to work fine for the Movie. But I can't figure out the binding for the Actors array.
<ItemsControl x:Name="MovieList">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Width="100">
<Border Margin="2">
<TextBlock Text="{Binding Movie, Mode=OneWay}" />
</Border>
<ListBox ItemsSource="{Binding Actors, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Any suggestions?
<ListBox ItemsSource="{Binding Actors, Mode=OneWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
this is wrong...you have to tell it what you want to bind to in the actors collection.
{Binding Path=ActorName} for example...since you only have it one way you could use displaymemberpath instead and just go: DisplayMemberPath="ActorName"