getting the Mouseover Event on listview in wpf - c#

I had created the listview in below manner
using grid view init;
i need that when mouseover on the gridview item i need to get that username details in the popup window , i am able to generate the popupwindow
except that Hover username in the listview
this is my sample code so please try to provide this information
<ListView AlternationCount="2" removed="#FFB6CCD8" Canvas.Left="15" Canvas.Top="77" FontSize="13" Height="43" IsSynchronizedWithCurrentItem="True" ItemContainerStyle="{DynamicResource ListViewItemContainerStyle}" ItemsSource="{Binding}" Name="checkedListView1" SelectionMode="Single" TabIndex="2" Width="269" ItemTemplate="{StaticResource ItemDataTemplate}"
SelectionChanged="checkedListView_SelectionChanged" MouseEnter="checkedListView1_MouseEnter" MouseMove="checkedListView1_MouseMove">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=empid}" Header="CardID" Width="1" />
<GridViewColumn DisplayMemberBinding="{Binding Path=username}" Width="200" />
<GridViewColumn >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Source="/WPF.Themes.Demo;component/Images/Status-user-online.ico" Width="20" Height="20"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
here i am using the listview in the Gridview manner , so please try to provide the Information to get the Username which was presented in the Gridviewcolumn when mouse cursor Hover in the listview
Thank you.

Related

Tabbing to textbox on row selected in pure XAML

I'm working on some XAML/WPF where we create a template of the form that then get compiled into a dll and this dll is then used by a blackbox application to render the form to the user.
Ideally, I should be able to this entirely in XAML, but I am not fully aware of what can and cannot be done in XAML.
I have the following:
<cad:SortableListView.View>
<GridView DataGridRow.Selected="">
<GridViewColumn Header="Message #" cad:SortableListView.SortPropertyName="MessageId" DisplayMemberBinding="{Binding Path=MessageId}"/>
<GridViewColumn Header="Critical" cad:SortableListView.SortPropertyName="Message.IsReceiptRequested" CellTemplate="{StaticResource criticalCellTemplate}"/>
<GridViewColumn Header="Date/Time" cad:SortableListView.SortPropertyName="Message.SendingTime" DisplayMemberBinding="{Binding Path=Message.SendingTime.LocalDateTime, StringFormat={}{0:G}}"/>
<GridViewColumn Header="Subject" cad:SortableListView.SortPropertyName="Message.Subject" DisplayMemberBinding="{Binding Path=Message.Subject}" Width="140"/>
<GridViewColumn Header="From Terminal" cad:SortableListView.SortPropertyName="Message.SendingTerminal" DisplayMemberBinding="{Binding Path=Message.SendingTerminal}"/>
<GridViewColumn Header="Sender" cad:SortableListView.SortPropertyName="Message.SendingEmployeeId" DisplayMemberBinding="{Binding Path=Message.SendingEmployeeId}"/>
<GridViewColumn Header="Priority" cad:SortableListView.SortPropertyName="Message.Priority" DisplayMemberBinding="{Binding Path=Message.Priority}"/>
<GridViewColumn Header="Event" cad:SortableListView.SortPropertyName="Message.LocalEvent.AgencyEventId" DisplayMemberBinding="{Binding Path=Message.LocalEvent.AgencyEventId}"/>
</GridView>
</cad:SortableListView.View>
....
More code
....
<TextBlock Grid.Row="3" Grid.Column="0" TextAlignment="Left" Margin="25,0,0,5">
Reply:
</TextBlock>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=ReplyText}" HorizontalAlignment="Stretch" Margin="10,0,30,5"/>
<Button Grid.Row="3" Grid.Column="2" Margin="5,0,30,5" DockPanel.Dock="Right"
Command="{Binding Path=Acknowledge.Command}"
cad:CreateCommandBinding.Command="{Binding Path=Acknowledge}" IsDefault="True">
Acknowledge
</Button>
I need it so that when a row is selected from the grid, the cursor has to jump to the text box and when "Enter" is pressed, the button click event is fired. I think I managed to do that by setting it as the default (IsDefault = "true"). Its the only button on the screen so I'm not too worried about something else firing.
Again, the ideal is to be able to do this in pure XAML, but if a file needs to be attached, kindly show me how to reference this code behind file.
Thank you

WPF ListView - 2 dimensions with 1 same structure

We are working on a ListView (C# WPF) and we didn't found how bind a list of items in columns, with each item containing itself a list of items with the same columns.
Let's illustre this in an example :
!
We got an observable collection on objects with parameters (name, etc.) and each object contain another observable collection of objects with the sames parameters (exept they haven't a list). So we want to list it in a ListView but we can't figure how !
We do not know enough ListView to implement this structure, some advices ?
Thanks in advance
I think the best way is :
XAML :
<Window.Resources>
<DataTemplate x:Key="gridViewSecondCellTemplate1">
<StackPanel Width="100">
<TextBlock Text="{Binding Content}" FontSize="15" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="gridViewCellTemplate1">
<StackPanel Width="100">
<TextBlock Text="{Binding Title}" FontSize="15" />
<ListView ItemsSource="{Binding MySecondSource}>
<ListView.View>
<GridView>
<GridViewColumn Header="{Binding Subtitle}" CellTemplate="{StaticResource gridViewSecondCellTemplate1}"/>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</DataTemplate>
</Window.Resources>
<ListView ItemsSource="{Binding MySource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Col 1" Width="100" CellTemplate="{StaticResource gridViewCellTemplate1}"/>
</GridView>
</ListView.View>
</ListView>
I didn't try this code. Try it, and say me if it is OK.

How to prevent listview items checkbox to be de-selected clicking out of checkboxes?

I've been messing around with checkboxes and listview in my wpf application. Selecting multiple items seems to work properly, but when I click on an item and not on its checkbox it selects the item and deselects all the others previously selected, how can I fix this ?
Here's my code:
<ListView Name="NewPlace_ActionsList" HorizontalAlignment="Left" Height="254" Margin="10,74,0,0" VerticalAlignment="Top" Width="389" >
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding Id}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Codice" DisplayMemberBinding="{Binding Path=Id}" />
<GridViewColumn Header="Nome" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Header="Descrizione" DisplayMemberBinding="{Binding Path=Desc}" />
</GridView>
</ListView.View>
</ListView>
What do you want to accomplish? The system behaves exactly to what you coded: the checkbox is selected only in the selected row. Because the Checkbox "follows" the IsSelected of the row (ListViewItem).

Add multiple items in a listbox row

So far i have been working with listview without any problem. I have been able to pass multiple columns and fill them with images, text etc. I decided to do the same thing with a listbox but things there got complicated.
In a listview i do the following :
<DataTemplate x:Key="ImageTemplate" >
<Image x:Name="FavoriteImageList" Tag="{Binding tagger}" Width="12" Height="12" Source="{Binding ImageSource}" MouseLeftButtonDown="FavoriteImageList_MouseLeftButtonDown"/>
</DataTemplate>
<ListView x:Name="Citys">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
<GridViewColumn Width="90" Header="Image" CellTemplate="{StaticResource ImageTemplate}"/>
<GridViewColumn Width="178" Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="178" Header="City" DisplayMemberBinding="{Binding City}"/>
<GridViewColumn Width="140" Header="Author" DisplayMemberBinding="{Binding Author}"/>
</GridView>
</ListView.View>
</ListView>
And i fill columns like this :
foreach(var fav in Favorites)
{
Citys = new List<ACity>()
{
new ACity() {tagger = Name ,ImageSource = ImageSource ,Name= Name, Author= Author, City = City}
};
ListBox.Items.Add(Citys);
}
If I do this in a listbox, it will fill with (Collection).
Is there a way to do this in a listbox, passing images buttons strings in a listbox row?
See the example from the MSDN ItemsControl.ItemTemplate
<ListBox Width="400" Margin="10"
ItemsSource="{Binding Source={StaticResource myTodoList}}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=TaskName}" />
<TextBlock Text="{Binding Path=Description}"/>
<TextBlock Text="{Binding Path=Priority}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
It should be pretty straight forward to match with your example.

WPF - ListView - GridView - Access CommandParameter from .xaml.cs file

I am using listview contain gridview to bind the data.
How I can use CommandParameter present on button from my .cs file. The button is present inside my gridview. Also how to identity each row by id from my .cs file on button click event.
My code:
<ListView Name="listUsers" SelectionMode="Single" Height="200" SelectionChanged="listUsers_SelectionChanged">
<ListBoxItem></ListBoxItem>
<ListView.View>
<GridView AllowsColumnReorder="true">
<GridViewColumn Header="User Id" DisplayMemberBinding="{ Binding Path=UserId }"></GridViewColumn>
<GridViewColumn Header="Name" DisplayMemberBinding="{ Binding Path=UserName }"></GridViewColumn>
<GridViewColumn Header="Email Id" DisplayMemberBinding="{ Binding Path=Email }"></GridViewColumn>
<GridViewColumn Header="Mobile" DisplayMemberBinding="{ Binding Path=Mobile }"></GridViewColumn>
<GridViewColumn Header="Update" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Height="23" Name="button1" CommandParameter="{ Binding Path=UserId }" Click="button1_Click" Width="75">Button</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
You'll need to create a Command (subclass of ICommand) and set your button command attribute to it.
You are using a click event, so i doubt the command parameter will be available when you handle the event.
if you are only interested in this UserId field and not other features of Command (like CanExecute etc), you can just use the Tag property of the button as you can get this via the code behind.
<Button Height="23" Name="button1" Tag="{Binding Path=UserId }" Click="button1_Click" Width="75">Button</Button>
In your button1_click event you can just access
var UserID = ((Button)sender).Tag; //cast the actual button in the grid

Categories