I would like to search items in my ListBox by typing. I found it can be done by TextSearch Property.
ListBox XAML:
<ListBox x:Name="SzablonyBox" HorizontalAlignment="Center"
HorizontalContentAlignment="Center" VerticalAlignment="Center"
MinWidth="100" MinHeight="100" BorderBrush="{x:Null}"
Background="{x:Null}" TextSearch.TextPath="Text" IsTextSearchEnabled="True">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="PreviewKeyDown" Handler="ListBoxItem_PreviewKeyDown"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding nazwa}" FontWeight="Bold"
FontSize="15" Height="35"
VerticalAlignment="Center" HorizontalAlignment="Center"
TextAlignment="Justify"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How to set TextSearch.TextPath="Text" to look after ListBox items (TextBlock text) ?
Related
I am binding a PivotItems but somehow the items are not resized properly, according to my margin declaration. Why is that?
EDIT: here is my new code and it still has gaps..
<Pivot x:Name="TpsSegmentsPivot" Title="Locator" Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Margin="0" Grid.Row="1" ItemTemplate="{StaticResource TpTemplate}" ItemsSource="{Binding DataSource}">
<Pivot.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding id}" Margin="0, 16, 0, 0" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
</Grid>
</DataTemplate>
</Pivot.HeaderTemplate>
</Pivot>
This is the template:
<DataTemplate x:Key="TpTemplate">
<ListBox Background="Black"
ItemsSource="{Binding Seg}"
ItemTemplate="{StaticResource SectionUCTemplate}"
HorizontalAlignment="Stretch"
VerticalAlignment="Top">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</DataTemplate>
Here is a screenshot with the red pivotItem..
I think the issue with the extra space is the Piviot Item you are using inside the DataTemplate tag. remove it and bind the header to a header template. I've used data binding on Pivots before and never seen this issue.
From one of my released apps:
<controls:Pivot Title="CAMPING CHECKLIST" ItemsSource="{Binding FilteredCategories}" Name="MainPivot">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<!-- Your pivot item content here -->
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
I believe the PivotItem in a PivotItem is the root of your issue.
your code should look similar to:
<controls:Pivot ItemsSource="{Binding tripTypeViewModel.TripTypeViewModelDataSource}" x:Name="TripsSegmentsPivot" Title=" " Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Grid.Row="1">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding DataContext.tripTypeViewModel.HeaderText, ElementName=TripsSegmentsPivot}" Margin="0, 16, 0, 0" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox x:Name="ItemsLB" ItemsSource="{Binding DataContext.tripTypeViewModel.Segment, ElementName=TripsSegmentsPivot}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<local:SectionUC HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Top"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
The first image is how I describe it, the second is how you currently have it :
This is the standard behaviour for PivotItems since they are always displayed with a margin. You should set a negative margin:
margin="-20,0,-20,0"
I have a ListView bound to an ObservableCollection and when items are added to the ListView, if you hover over a ListViewItem, you will see that not only the ListViewItem itself if highlighted, but there is also another slightly-smaller, darker-blue rectangle that appears. Now this slightly smaller rectangle prevents you from being able to select the ListViewItem because it is on-top of the ListViewItem.
Why is it there and how do I get rid of it?
<Grid Margin="0, 25, 0, 22" Grid.Column="0">
<ScrollViewer ScrollViewer.CanContentScroll="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<ListView x:Name="list" ItemsSource="{Binding Source=Message}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<ListViewItem HorizontalAlignment="Stretch" Height="50">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Sender}" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis" TextWrapping="Wrap" FontWeight="SemiBold" />
<TextBlock Text="{Binding Subject}" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis" TextWrapping="Wrap" />
</StackPanel>
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
You have a ListViewItem in your ListViewItem. The ListView will automatically wrap it's items in a container so you don't have to do that. Remove the ListViewItem from your DataTemplate.
Remove ListviewItem from DataTemplate. ListView will wrap whatever is in your DataTemplate in ListViewItem. If you have something to set against ListViewItem do it through ItemContainerStyle
<ListView x:Name="list" ItemsSource="{Binding Source=Message}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderBrush="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch">
<TextBlock Text="{Binding Sender}" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis" TextWrapping="Wrap" FontWeight="SemiBold" />
<TextBlock Text="{Binding Subject}" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Height" Value="50"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
I'm totally new to wpf and silverlight, and I have A LOT to learn...
I've got a listbox which contain a template
<ListBox ItemsSource="{Binding itemList}" x:Name="list">
<ListBox.ItemTemplate>
<DataTemplate x:Name="datatemplate" >
<Grid Name="{Binding Id}">
<TextBlock Text="{Binding Txt}"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
i need to assign a AutomationProperties.AutomationId to each list item, like in
<ListBoxItem x:Name="lb_a" AutomationProperties.AutomationId="lb_1">
<Grid Name="grid_a">
<TextBlock Text="aa"></TextBlock>
</Grid>
</ListBoxItem>
<ListBoxItem x:Name="lb_b" AutomationProperties.AutomationId="lb_2">
<Grid Name="grid_b">
<TextBlock Text="bb"></TextBlock>
</Grid>
</ListBoxItem>
...
how can i do?
is that even possible?
You can set your attached property in ItemContainerStyle:
<ListBox ItemsSource="{Binding itemList}" x:Name="list">
<ListBox.ItemTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="AutomationProperties.AutomationId" Value="{Binding MyAutomationIdProperty}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
I am having a problem, I have a datatable data with 3 columns(ID,NAME,QUANTITY), I want to bind it with a ListBox, and make ListBox shows values from column NAME and QUANTITY,otherwise when I double click in a selected item,it will send ID value, here is my XAML:
<ListBox HorizontalAlignment="Left" Margin="6,0,0,0" Name="ListBox1" VerticalAlignment="Top" Height="600" Width="321">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseDoubleClick" Handler="ListBox1Item_DoubleClick" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.Resources>
<DataTemplate x:Key="listBoxTemplate">
<DockPanel >
<TextBlock FontWeight="Bold" Text="{Binding NAME}"
DockPanel.Dock="Left"
Margin="5,0,10,0" Width="100"/>
<TextBlock Text="{Binding QUANTITY} " Foreground="Green" FontWeight="Bold" />
</DockPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox>
Here is my code behind:
...
ListBox1.ItemsSource = data.DefaultView;
ListBox1.SelectedValuePath = "ID";
...
But it does not show anything, something wrongs? please help! thanks for reading this!
You need to set the ListBox.ItemTemplate.
At the moment you are defining a template with a key, that template is not being used anywhere.
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel >
<TextBlock Text="{Binding NAME}" FontWeight="Bold"
DockPanel.Dock="Left"
Margin="5,0,10,0" Width="100" />
<TextBlock Text="{Binding QUANTITY}" FontWeight="Bold"
Foreground="Green" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
I have a ListBox that is bound to a TabControl. Some of the TabItems inside this (TabControl) are hidden/disabled then become visible/enabled when I open a file.
My issue is that these hidden/disabled items are still visible in my ListBox. Can someone help me with regards as to why this is happening?
TabControl XAML
<TabControl Height="Auto" x:Name="tabControl" Width="Auto"
Padding="0" Margin="3" DataContext="{Binding}">
<TabItem Header="StartPage" x:Name="StartTab" Foreground="White" Height="25">
</TabItem>
<TabItem Header="DragDrop" x:Name="DragDropTab" Foreground="White"
Height="25" IsEnabled="False" Visibility="Hidden">
<Image Height="Auto" x:Name="DragImage" Stretch="Fill" Width="Auto" />
</TabItem>
<TabItem Header="Text" x:Name="TextTab" Foreground="White"
Height="25" IsEnabled="False" Visibility="Hidden" >
<Grid>
<cbox:SyntaxHighlightBox Height="Auto" x:Name="HighlightText"
Width="Auto" Text="" AcceptsTab="True" AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Visible" />
</Grid>
</TabItem>
</TabControl>
ListBox XAML
<ListBox ItemsSource="{Binding Items, ElementName=tabControl}"
x:Name="ShowOpenTabs" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseDoubleClick" Handler="OpenOnClick"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You need to bind the ListBox item visibility to the tabcontrol item visibility
<DataTemplate>
<TextBlock Text="{Binding Header}" Visibility="{Binding Path=Visibility}"/>
</DataTemplate>