Listview Trouble - Tooltip Needed - c#

I am building a WPF application in C# using VS2010
I have a listview that contains items from a database , and each item contains a field called (Name) and another field called (Time) .
Back in the database , each item has a third field called (Description) too ...
Now what I want is :
When I choose an item from the listview , a tooltip is shown and it contains the data from the third field ..
How can I have various tooltips on one listview - one tooltip for each item - ??
How can I deal with my database ??
Thank You

Setting the Tooltip for a ListViewItem can be done like this
<ListView ...>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="ToolTip" Value="{Binding Path=Name}"/>
</Style>
</ListView.ItemContainerStyle>
<!-- ... -->
</ListView>

Related

Extended combobox control

I need a control which extremelly looks like combobox from win run window.
My question is is it a standart combobox control with specific settings or I have to create a custom control in order to achieve this appearance and behavior ?
I'm interested in appearance and behaviour next to the third image - like filtered suggestions which shown as listbox in a popup after pressing a key.
standart combobox
combobox open
the most interresting - like filtered suggestions
UPDATED!
Is it a standard combobox control ?
As you can see in the attached gif below when I start inputting something combobox looks like a textbox with popup window under it which contains filtered items. Like a sort of mix between textbox, combobox and popup window with listbox
This is already built into the ComboBox. Here is an example:
<ComboBox
IsEditable="True" //This enables to enter values that don't belong to the ItemsSource collection
IsTextSearchEnabled="True" //this allows you to have "suggestions" when you enter text
IsTextSearchCaseSensitive="False"
StaysOpenOnEdit="True"
Text="{Binding NameOnViewModel}"
TextSearch.TextPath="NameOnChildItems" //this is the property on which combobox will filter the items
ItemsSource="{Binding Items}" //collection of your items to search on
ItemTemplate="{StaticResource DataTemplate}" />//this can be replaced with DisplayMemeberPath="PropertyName"
Note:
This example was taken from this SO post.
EDIT
In case you want the popup to open when you are typing in the values then this could be of help:
</ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">//you can also use a different event if this one doesn't suit your needs.
<Setter Property="IsDropDownOpen" Value="true" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
EDIT 2
For filtering of the VISIBLE objects in the drop down list of your combobox then use the key down event and filter it in the event handler like so:
private void cmbKeyDown(object sender, KeyEventArgs e)
{
string temp = ((ComboBox)sender).Text;
var newList = MyList.Where(x => x.Name.Contains(temp));
MyList = newList.ToList();
}

Setting ListViewItem property IsEnabled based on attribute of item

I am trying to define the IsEnabled Property on each ListViewItem in the ListView based on the value of an attribute of the item itself. The xaml below will allow me to bind to a property of the page's datacontext, but not to one of the indiviual item being displayed.
<ListView Height="450" ItemsSource="{Binding ItemCollection}" ItemClick="ItemSelected" IsItemClickEnabled="True" SelectionMode="None" FontFamily="Global User Interface">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="IsEnabled" Value="{Binding MarkedOffNotRemoved}"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
With the property on the Item Type
public Boolean MarkedOffNotRemoved
{
get
{
return MarkOff == null || !MarkOff.Removed;
}
}
With the code like this, the error I see is from ReSharper (Not VisualSTudio) and it is a "Cannot resolve property in the Data context" error. The error also indicates the context it is looking at is the ViewModel for the page, not the individual items. VisualStudio compiles the code without error, however the page does not behave as expected and when debugging the get for MarkedOffNotRemoved is not called at all.
Is there a way to change my binding to an attribute of each item in the collection such that the binding property will actually be called? Or will I need to use an ItemContainerStyleSelector along with a style for enabled items and a style for disabled items?

Binding Converter using index of item in list

I have a scenario which requires me to bind a list of objects to a grid. I would like the behaviour as such that :-
• When an item is added to the list it moves to the next available space in the grid. (like a wrap panel)
Shown below is my current XAML.
<ItemsControl ItemsSource="{Binding Path=Contents}" Grid.Row="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<cc:DynamicGrid ShowGridLines="True" RowCount="{Binding Path= SelectedGridStyle.RowCount}" ColCount="{Binding Path=SelectedGridStyle.ColCount}"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Currently this puts all of the items on top of each other because I have not specified a row index or column index. I plan to add the following to rectify this
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column" Value="{Binding Path=ColumnIndex}"/>
<Setter Property="Grid.Row" Value="{Binding Path=RowIndex}"/>
<Setter Property="Grid.ColumnSpan" Value="{Binding Path=ColumnSpan}"/>
<Setter Property="Grid.RowSpan" Value="{Binding Path=RowSpan}"/>
</Style>
</ItemsControl.ItemContainerStyle>
I have the following code which will allow me to calculate the rowIndex and columnIndex from the index in the list.
int m_ColumnCount = 3;
int rowIndex = index / m_ColumnCount;
int columnIndex = index - (rowIndex * m_ColumnCount);
I am attempting to create a binding converter using the above to set these values. However this calculation depends on values held in the view model for the number of columns and rows. Is there a way to get these values?Can the above be achieved or is there a better solution?
Check out this - http://www.switchonthecode.com/tutorials/wpf-tutorial-using-multibindings
You will see about half way down the use of the multibinding, it's pretty simple. Then they show you how to create a converter for it. Sounds like you are familiar with converters so I think that article will get you moving.
If a binding needs more than one value you could use a MultiBinding. To bind to the main viewmodel you can use a RelativeSource targeting the ItemsControl.

Select Multiple items in listbox in wpf using c#

I want to set multiple selection in a ListBox using c#.
For example, I have a list of values I want to set these values as selected in the ListBox.
How can I do this?
MyListBox.SelectedItems.Add(item1);
MyListBox.SelectedItems.Add(item2);
.....
You did not explain much, hopefully your are doing this the WPF way...
Create an IsSelected property on your data items then give the style to your ListBoxItems that selects them whenever the IsSelected is enabled:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected" Value="{Binding IsSelected}"/>
</Style>
</ListBox.ItemContainerStyle>
Then change the property on your data items, and raise the OnPropertyChanged event.

Combobox DropDownOpened event

I have a combo box inside a list view. And different items (rows) in the list view need to display (based on some condition) one among 3 sets of combo box items in the respective combo box which is . Right now I am achieving this by using 3 data templates bound to 3 different properties of List<string>. I am hooking up the appropriate data templates during the DropDownOpened event of the combo boxes.
The problem that I am facing is that I am having to click the combo box twice each time to have it dropped down. I did a Debug.WriteLine() to see if my first click does the job of selecting a data template, I found that it indeed does. But just that it does not drop down at the first click itself.
I guess this is because I am changing the data template after the combo box has dropped down its popup and hence it refreshes again whose results are furnished only after I perform the second click.
My question is whether there is any other way of accomplishing what I am trying or do I have to make any changes in my existing DropDownOpened event handler.
Please suggest.
EDIT : I'm using WPF
Thanks
Would it be an option to use styles to set the items? e.g.
<ComboBox>
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding SomeConditionalProperty}"
Value="SomeConditionalValue">
<Setter Property="ItemsSource" Value="{BindingToFindRightItems}"/>
</DataTrigger>
<DataTrigger Binding="{Binding SomeConditionalProperty}"
Value="AnotherValue">
<Setter Property="ItemsSource" Value="{BindingToFindRightItemsForAnotherValue}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>

Categories

Resources