I'm trying to put any selected item's name in my list box in the textbox next to it. But I've got trouble doing so.
Here's a little bit of my code:
<DockPanel Margin="10">
<StackPanel Margin="5" DockPanel.Dock="Left">
<ListBox Name="lbNames" DisplayMemberPath="Name" IsSynchronizedWithCurrentItem="True"/>
</StackPanel>
<StackPanel Margin="5" DockPanel.Dock="Right">
<TextBox Name="txtName" Width="auto" Text="{Binding ElementName=lbNames,Path=SelectedItem}"/>
<WrapPanel Margin="0,5" Orientation="Horizontal">
<Button Margin="2,0" Name="btnAdd" Click="btnAdd_Click" Content="Add"/>
<Button Margin="2,0" Name="btnEdit" Click="btnChange_Click" Content="Edit"/>
<Button Margin="2,0" Name="btnDelete" Click="btnDelete_Click" Content="Delete"/>
</WrapPanel>
</StackPanel>
</DockPanel>
Because you are showing Text="{Binding ElementName=lbNames,Path=SelectedItem}"and your selected item is an user object.
Instead of this you can use something like that.
First add SelectedValuePath="Name" into your listbox.
Then use Text="{Binding ElementName=lbNames,Path=SelectedValue}"
<DockPanel Margin="10">
<StackPanel Margin="5" DockPanel.Dock="Left">
<ListBox Name="lbNames" DisplayMemberPath="Name" SelectedValuePath="Name" IsSynchronizedWithCurrentItem="True"/>
</StackPanel>
<StackPanel Margin="5" DockPanel.Dock="Right">
<TextBox Name="txtName" Width="auto" Text="{Binding ElementName=lbNames,Path=SelectedValue}"/>
<WrapPanel Margin="0,5" Orientation="Horizontal">
<Button Margin="2,0" Name="btnAdd" Click="btnAdd_Click" Content="Add"/>
<Button Margin="2,0" Name="btnEdit" Click="btnChange_Click" Content="Edit"/>
<Button Margin="2,0" Name="btnDelete" Click="btnDelete_Click" Content="Delete"/>
</WrapPanel>
</StackPanel>
</DockPanel>
Or simply you can use it too Text="{Binding ElementName=lbNames,Path=SelectedItem.Name}"
Related
I'm trying to highlight the selected item in a bridview from a windows application.
To be more precise:
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemsGridView"
AutomationProperties.Name="Items"
TabIndex="1"
Grid.RowSpan="2"
Padding="116,136,116,46"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="True"
ItemClick="openRessource"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}">
<GridView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left" Width="200" Height="250" Holding="openHoldMenu">
<Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
<Image Source="{Binding icon}" Stretch="None"/>
</Border>
<Image Source="{Binding downloaded}" Width="30" Height="30" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Top"/>
<StackPanel VerticalAlignment="Bottom" Background="{ThemeResource ListViewItemOverlayBackgroundThemeBrush}">
<TextBlock Text="{Binding Mode=OneWay}" Foreground="{ThemeResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" Height="60" Margin="15,0,15,0" FontWeight="SemiBold"/>
<TextBlock Text="{Binding description, Mode=OneWay}" Foreground="{ThemeResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource BaseTextBlockStyle}" TextWrapping="NoWrap" Margin="15,0,15,10" FontSize="12"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
This is my XAML, fairly simple, I just have a Holding event which brings up a menu in my page.
My problem is that I want to know which item has been held to create a border around it so that the user knows which item is selected.
I can easily access the bound item in my list but can't get the grid element selected.
If anyone know how to, that would be really appreciated.
Thank you!
Should be able to make a trigger such as this:
http://stackoverflow.com/questions/4539909/wpf-datagrid-selected-row-style
I'm creating a list of images in a listbox, but i need the images to be clickable.
What I'm having trouble with is getting the value from the child element(textblock) when you click the image.
I have searched all over the net, but i cannot find the solution.
`
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Margin="10" Grid.ColumnSpan="2">
<TextBlock FontFamily="Tunga" FontSize="30" Foreground="White" Text="WOW" />
<TextBlock FontFamily="Tunga" FontSize="25" Foreground="White" Text="Work Out Warz" />
</StackPanel>
<StackPanel Grid.Column="4" Grid.Row="0">
<TextBlock FontFamily="Tunga" FontSize="36" Foreground="White" Text="" Name="txtname" Height="45"/>
<TextBlock FontFamily="Tunga" FontSize="25" Foreground="White" Text="" Name="txtwowid" />
</StackPanel>
<Grid Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="5" >
<ListBox x:Name="LstImages" Background="Gray" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.PanningMode="HorizontalOnly" Cursor="Hand" SelectionChanged="LstImages_SelectionChanged" IsSynchronizedWithCurrentItem="True" >
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<StackPanel Orientation="Vertical" Margin="10" >
<Button Click="Button_Click" >
<Image Source="{Binding img}" Height="250"/>
</Button>
<TextBlock Name="txtblname" Text="{Binding Title}" Foreground="White" FontSize="30" FontFamily="Tunga"/>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
`
In order to get the selected item you can bind SelectedImage in your dataContext object which should have Title and img properties to SelectedItem property of ListBox
<ListBox SelectedItem="{Binding Path=SelectedImage, Mode=TwoWay}" x:Name="LstImages" Background="Gray" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.PanningMode="HorizontalOnly" Cursor="Hand" SelectionChanged="LstImages_SelectionChanged" IsSynchronizedWithCurrentItem="True" >
i have a list box view in windows phone that i want to delete an item from it upon a specified event .... how can i accomplish that
this is my XAML code
<ListBox x:Name="lstData2"
ItemsSource="{Binding DataCollection2, Source={StaticResource PinsCollection}}" Grid.ColumnSpan="3" Foreground="#FF1D53D0" Height="583" VerticalAlignment="Bottom">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Tap="StackPanel_Tap">
<Image Margin="8"
VerticalAlignment="Top"
Source="{Binding ImageUri}"
Width="100"
Height="100" />
<StackPanel Height="93" Width="259" >
<TextBlock Margin="8"
Width="250"
TextWrapping="Wrap"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Foreground="#FF1D53D0"
Text="{Binding Pinnedname}" Height="33" RenderTransformOrigin="0.5,0.5" FontFamily="Segoe WP SemiLight" FontSize="24" FontWeight="Bold" />
<TextBlock Width="155"
Margin="8,0,8,8"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Text="{Binding Status}" Foreground="#FF1D53D0" FontFamily="Segoe WP SemiLight" />
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Remove Pin" Click="RemovePin_Click" Tag="{Binding pinId}"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You are using binding to show your data (DataCollection2) in a list view. Your list view is updated when your data is modified. To delete an item in the ListView, you should remove the corresponding item in the DataCollection2 and the list view will be automatically updated. Make sure that the DataCollection2 is an ObservableCollection instance.
I am building an application for Windows Phone 7 where i am displaying a few data in listbox. I want to add an image after each item to distinguish it from another. My xaml code is:
<ListBox Name="listBox1" BorderThickness="0" Height="679" VerticalAlignment="Bottom" Margin="12,0,0,-29" Background="White" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Height="80" Width="400">
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" Background="White" Width="500">
<Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,20,10" Height="100" Width="145" />
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding city_name}" Foreground="Red" FontFamily="Verdana" />
<TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
<TextBlock Text="{Binding state}" Foreground="Red" FontFamily="Verdana" />
</StackPanel>
<TextBlock Text="{Binding Path=city_description}" TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana"></TextBlock>
<Image Source="Image/index.jpg"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The index.jpg image is the horizontal line i wanted to add. Please help where to add that image so that i get that image as a separator for each data
Check this:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/e09926c2-5d53-4337-ba76-d1c786ec9ced/listbox-with-horizontal-lineseparator?forum=wpf
1st answer
Try something like this:
<ListBox Name="listBox1" BorderThickness="0" Height="679" VerticalAlignment="Bottom" Margin="12,0,0,-29" Background="White" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Height="80" Width="400">
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" Background="White" Width="500">
<Image Source="{Binding ImageBind }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,20,10" Height="100" Width="145" />
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding city_name}" Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
<TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
<TextBlock Text="{Binding state}" Foreground="Red" FontFamily="Verdana" />
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
</StackPanel>
<TextBlock Text="{Binding Path=city_description}" TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana"></TextBlock>
<Separator Width="{Binding ElementName=listBox1, Path=ActualWidth}"/>
<Image Source="Image/index.jpg"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This will help you ;)
I have to get the suggestion list in the autocomplete textbox.I give the input as binding names..You can see in the xaml code in the listbox i can bind the names from Img source..but in the autocomplete i cant.. guide me that should i have to insert any code for this in Mainpage.cs
<ColumnDefinition Width="400"/>
</Grid.ColumnDefinitions>
</Grid>
<Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="12,6,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
<ListBox HorizontalAlignment="Stretch" Name="listBox1" VerticalAlignment="Stretch" ItemsSource="{Binding Img}" Grid.Row="1" DataContext="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Height="160" HorizontalAlignment="Left" Margin="0,0,-400,0" VerticalAlignment="Top" Width="175" Source="{Binding thumb}"/>
<!--ContentControl Width="150" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,-400,0" Content="{Binding Image}"/>-->
<TextBlock TextWrapping="NoWrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="190,-167,-200,0" Text="{Binding title}"/>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="190,-135,-200,0" Text="{Binding page}"/>
<TextBlock FontSize="16" TextWrapping="Wrap" Margin="190,-95,0,0" Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox Height="72" HorizontalAlignment="Left" Margin="157,6,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="112" />
<toolkit:AutoCompleteBox HorizontalAlignment="Left" Margin="261,6,0,0" Name="autoCompleteBox1" VerticalAlignment="Top" Width="182" ItemsSource="{Binding Img}" ValueMemberBinding="{Binding Name}">
<toolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel >
<TextBlock
Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
</toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>
</Grid>
I solved this issue, I changed the xaml as
</TextBox>
<toolkit:AutoCompleteBox HorizontalAlignment="Left" FilterMode="Contains" Margin="-11,-14,0,0" Name="autoCompleteBox1" ValueMemberBinding="{Binding Name}" VerticalAlignment="Top" Width="800" Background="White" Height="91" Text="" TextChanged="autocompletebox1_Textchanged" BorderBrush="White" Visibility="Visible" Padding="50,14,6,4" BorderThickness="0" IsHitTestVisible="True">
<toolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Width="250" TextWrapping="Wrap" Margin="25,25,0,0" FontSize="20" Text="{Binding Name}" />
<Image Height="110" Width="150" Source="{Binding Image1}" />
</StackPanel>
</DataTemplate>
</toolkit:AutoCompleteBox.ItemTemplate>
</toolkit:AutoCompleteBox>