In my project I use list view and want to get the object from double click event,
I mean when user click on listview row, then from viewmodel I want to get the clicked object.
XAML:
cal:Message.Attach="[Event MouseDoubleClick] = [Action RowDoubleClick($dataContext)]"
ViewModel
public void RowDoubleClick(object pm)
{
}
but in object pm in ViewModel I get all off the listview object, I need a single object.
Can anyone help me regarding this issue.
XAML
<ListView AlternationCount="2" HorizontalAlignment="Center" cal:Message.Attach="[Event MouseDoubleClick] = [Action RowDoubleClick($dataContext)]"
Name="lvProcessList" SelectionChanged="lvProcessList_SelectionChanged"
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True"
VerticalAlignment="Top" Width="779" Grid.ColumnSpan="8" IsSynchronizedWithCurrentItem="True" Height="391" >
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" >
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="0,0,1,1" />
<Setter Property="Height" Value="30" />
<Setter Property="IsSelected" Value="{Binding chkWspSelect}"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="SteelBlue"/>
</Trigger>
</Style.Triggers>
<!--<EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />-->
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn>
<DataGrid AutoGenerateColumns="True" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTemplateColumn >
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<CheckBox Name="chkWspSelectAll" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="chkWspSelectAll_Checked" Unchecked="chkWspSelectAll_Unchecked" IsThreeState="False"/>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<GridViewColumn.CellTemplate >
<DataTemplate>
<CheckBox Name="chkWspSelect" HorizontalContentAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="chkWspSelect_Checked" Unchecked="chkWspSelect_Unchecked" IsThreeState="False"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="200" Header="Process name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" Text="{Binding ProcessName}" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="120" Header="Ongoing">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Ongoing}" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="110" Header="Un-Strated">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Un-Strated}" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="110" Header="Completed">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Completed}" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="200" Header="Action" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<WrapPanel >
<Button Width="50" Height="25" Margin="30,0,0,0" x:Name="btnDelete" Click="BtnDelete_Click">
<StackPanel Orientation="Horizontal" >
<Image Source="/Pipe_Flushing;component/Image/Trash.png" Height="20"/>
</StackPanel>
</Button>
<Button x:Name="btnHistory" Width="50" Height="25" Margin="10,0,0,0" Click="BtnHistory_Click">
<StackPanel>
<Image Source="/Pipe_Flushing;component/Image/History.png" Height="20"/>
</StackPanel>
</Button>
<Button x:Name="btnHistory1" Width="50" Height="25" Margin="10,0,0,0" Content="test" cal:Message.Attach="[Event Click] = [Action Edit($dataContext)]">
</Button>
</WrapPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
Related
My ListView contains a textbox per column to change data. Via Style my Listview rows are colored in different colors depending on the alternation index.
I want my textboxes within the listview to look like the entire line.
Actually its like this:
The lines should cover the textboxes.
The Code to color the ListView Rows:
<Style x:Key="DifAlternationColorsLV" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#FFB1E4EF"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#FFD4EBFF"></Setter>
</Trigger>
</Style.Triggers>
</Style>
The code in the XAML of the View:
<Border Grid.Row="1" Grid.Column="0"
Margin="10,10,10,10"
BorderBrush="#FF474A57"
CornerRadius="10,10,10,10"
BorderThickness="2,2,2,2"
Width="300"
MaxHeight="200"
Background="White">
<StackPanel Margin="0,0,0,20" Orientation="Vertical">
<StackPanel Grid.Column="0" Grid.RowSpan="1"
Grid.Row="1"
VerticalAlignment="Top">
<Label HorizontalAlignment="Center" FontWeight="Bold">
Schichten
</Label>
<ListView x:Name="Shift" MinHeight="150" MaxHeight="150" MinWidth="250" HorizontalContentAlignment="Stretch" HorizontalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
ItemContainerStyle="{StaticResource DifAlternationColorsLV}"
AlternationCount="2"
ItemsSource="{Binding UiShiftHModelList, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding SelectedLine, UpdateSourceTrigger=PropertyChanged}" d:ItemsSource="{d:SampleData ItemCount=3}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Bezeichnung" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="Bezeichnung" MinWidth="100"
Style="{StaticResource TBoxInListV}"
Text="{Binding Bezeichnung, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0">
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Tagmuster" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<!---->
<TextBox x:Name="Tagmuster" MinWidth="80"
Background="{Binding ElementName=Shift}"
Style="{StaticResource TBoxInListV}"
Text="{Binding TagmusterID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0">
</TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Edit" Width="40">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="SaveShiftH"
Style="{StaticResource BtnListSave}"
Grid.Column="0">
</Button>
<Button x:Name="UpdateShiftH"
Style="{StaticResource BtnListUpdate}"
Grid.Column="0">
</Button>
<Button x:Name="DeleteShiftH"
Style="{StaticResource BtnListDelete}"
Grid.Column="1">
</Button>
<Button x:Name="ReopenShiftH"
Style="{StaticResource BtnListReopen}"
Grid.Column="0">
</Button>
</Grid>
</StackPanel>
<DataTemplate.Triggers>
<!--Visibility of the Buttons-->
<DataTrigger Binding="{Binding EditModus}" Value="0">
<Setter TargetName="SaveShiftH" Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding EditModus}" Value="2">
<Setter TargetName="UpdateShiftH" Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding EditModus}" Value="1">
<Setter TargetName="UpdateShiftH" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<DataTrigger Binding="{Binding EditModus}" Value="2">
<Setter TargetName="DeleteShiftH" Property="Visibility" Value="Visible"/>
</DataTrigger>
<DataTrigger Binding="{Binding EditModus}" Value="1">
<Setter TargetName="DeleteShiftH" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<!--<DataTrigger Binding="{Binding EditModus}" Value="0">
<Setter TargetName="Delete" Property="Visibility" Value="Collapsed"/>
</DataTrigger>-->
<DataTrigger Binding="{Binding EditModus}" Value="1">
<Setter TargetName="ReopenShiftH" Property="Visibility" Value="Visible"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</StackPanel>
</Border>
If I change the Background Binding from the Textbox to:
Background="{Binding ElementName=Shift}"
The Line appears exactly I want it to but leads to a lot binding errors.
Any ideas?
You can make the background of the TextBox wholly or partially transparent; that will make the background of the row visible:
<TextBox x:Name="Bezeichnung" MinWidth="100" Background="#60FFFFFF"
Style="{StaticResource TBoxInListV}"
Text="{Binding Bezeichnung, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0">
</TextBox>
I am trying to achieve some thing below in the image.
In the list, I would like to put the text "WS1", "WS2" "WS3" onto the image dynamically in the code depending on the some conditions. I have setup something in xaml. I am not sure if that will work and how to write the code to match the xaml.
<Style x:Key="AnnotationStyle" TargetType="TextBlock">
<Setter Property="Background" Value="#70FFFFFF" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
<DataTemplate x:Key="DisplayImage">
<StackPanel Width="50">
<StackPanel Orientation="Horizontal">
<Image Height="40" Source="{Binding ImageData}" />
<TextBlock Text="{Binding Description}" Style="{StaticResource AnnotationStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource checkbox}"/>
<GridViewColumn Header="Profile ID" DisplayMemberBinding="{Binding ProfileID}"/>
<GridViewColumn Header="Monitor 1" DisplayMemberBinding="{Binding DisplayImage}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
How do I implement this in the code and does this xaml work? thank you very much in advance.
<ListView>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<CheckBox />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn
Width="50"
DisplayMemberBinding="{Binding ProfileID}"
Header="Profile ID" />
<GridViewColumn Width="90" Header="Monitor 1">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Image
Width="50"
Height="40"
Source="{Binding DisplayImage}" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Text1}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="90" Header="Monitor 2">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Image
Width="50"
Height="40"
Source="{Binding DisplayImage}" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Text2}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="90" Header="Monitor 3">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Image
Width="50"
Height="40"
Source="{Binding DisplayImage}" />
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Text3}" />
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
I have a listview with buttons for each row, but when I bind the IsEnabled property to the SelectedIndex still keep enable all the buttons, I just need this one, and also I have another button that has to be enable depends on the property of the object in the listview.
e.g I have a class File that has a property bool HasLckFile, and I need that the download button keep disable until the user upload, but the binding is not working.
XAML:
<ListView x:Name="lv" Style="{StaticResource CustomListViewStyle}" Margin="470,0,0,0" SelectionMode="Multiple" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Tag="{Binding Filename}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Width="150">
<GridViewColumn DisplayMemberBinding="{Binding Filename}"/>
</GridViewColumn>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="download" VerticalAlignment="Center" Click="btnDownload">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=lv, Path=SelectedIndex}" Value="-1">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="upload" VerticalAlignment="Center" Click="btnUpload">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=lv, Path=SelectedIndex}" Value="-1">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
I want to display a List in a ListView with Master Detail View. The Master View works fine, but the binding to the detail view is not working. What am i doing wrong?
Code Behind:
DataContext = new VirtualizingCollection<LinesSummary>(fs, 100)
LinesSummary Class:
public class LinesSummary {
public string dateString { get; set; }
}
XAML:
<StackPanel>
<ListView Margin="5" Style="{DynamicResource lvStyle}" Height="200" x:Name="Master"/>
<ListView Margin="5" Style="{DynamicResource lvStyle_Detail}" Height="200" x:Name="Detail"/>
</StackPanel>
Dynamic Resource for Master View:
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
<Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="True"/>
<Setter Property="ListView.ItemsSource" Value="{Binding}"/>
<Setter Property="ListView.View">
<Setter.Value>
<GridView>
<GridViewColumn Header="Date" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding dateString}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</Setter.Value>
</Setter>
</Style>
Dynamic Resource for Detail View:
<Style x:Key="lvStyle_Detail" TargetType="{x:Type ListView}">
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
<Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="True"/>
<Setter Property="ListView.ItemsSource" Value="{Binding ElementName=Master, Path=SelectedItem.LinesSummary}"/>
<Setter Property="ListView.View">
<Setter.Value>
<GridView>
<GridViewColumn Header="aaa" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding dateString}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</Setter.Value>
</Setter>
</Style>
The ItemsSource of a ListView can only be bound to an IEnumerable so even if you bind the ItemsSource property of the second ListView like this it won't work:
ItemsSource="{Binding ElementName=Master, Path=SelectedItem}"
...because LinesSummary is not an IEnumerable.
Since there is only a maximum of one item selected in Master, you might as well bind a TextBlock to the dateString property of its SelectedItem:
<StackPanel>
<ListView Margin="5" Style="{DynamicResource lvStyle}" Height="200" x:Name="Master"/>
<ListView Margin="5" Style="{DynamicResource lvStyle_Detail}" Height="200" x:Name="Detail">
<ListViewItem>
<TextBlock Text="{Binding Path=SelectedItem.dateString, ElementName=Master}" />
</ListViewItem>
</ListView>
</StackPanel>
Remove this setter from the lvStyle_Detail:
<Setter Property="ListView.ItemsSource" Value="{Binding ElementName=Master, Path=SelectedItem.LinesSummary}"/>
I don't have access to a Macintosh to test this on (i.e, I can't load the Xamarin Mac components) so I don't have a way to test this. But...below is the XAML of a WPF app. Most everything in the app appears to be Xamarin-compliant -- WebClient calls, populating my form fields through an XMLDocument and binding, for instance -- but I don't know of the XAML is compliant. So, here it is:
<Window x:Class="IMManager.ImManagerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="IMM Media Manager"
SnapsToDevicePixels="True"
WindowState="Normal"
MaxWidth="720"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="AlternatingListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<!-- setting up triggers for alternate background colors -->
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="2">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
</Style.Triggers>
<!-- setting row height here -->
<Setter Property="Height" Value="25" />
</Style>
</Window.Resources>
<ListView x:Name="LvAlbums" ItemsSource="{Binding XPath=/downloads/Album}" Width="680">
<ListView.ItemTemplate>
<DataTemplate x:Name="dt1">
<StackPanel x:Name="spAlbum" HorizontalAlignment="Left">
<TextBlock
Text="{Binding XPath=#Artist,StringFormat='Artist: {0}'}"
FontSize="16px"
/>
<TextBlock
Text="{Binding XPath=#Name,StringFormat='Album: {0}'}"
FontSize="16px"
/>
<ListView x:Name="lvTracks" ItemsSource="{Binding XPath=Item}" ItemContainerStyle="{StaticResource AlternatingListViewItemStyle}" AlternationCount="2">
<ListView.View>
<GridView>
<GridViewColumn Header="Track" Width="460">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="trackName" Text="{Binding XPath=#Name}" Width="450" LineHeight="25" Height="25" VerticalAlignment="Center" Margin="0,3,0,0">
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Progress" Width="175">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Canvas VerticalAlignment="Center" Height="25">
<ProgressBar Foreground="GreenYellow" Name="PbStatus" Value="{Binding XPath=#Progress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Minimum="0" Maximum="100" Height="20" VerticalAlignment="Center" Margin="0,3,0,0" Width="165"/>
<TextBlock FontFamily="Segoe UI" LineHeight="25" FontWeight="Bold" Text="{Binding XPath=#Info, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Height="20" Width="165" VerticalAlignment="Center" Margin="0,4,0,0"/>
</Canvas>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Can Mac Xamarin handle this or something close to this?
No. Xamarin Mac does not use XAML. Xamarin Forms does, but it is a different syntax than the XAML used in WPF.