I still don't understand what you are trying to do or where this is not working. Can you share a minimum repro demonstrating what you are doing to your OneDrive, along with a clear explanation of expected results and how they differ from actual results.
My apologies for being vague.
I hope that this time I will be able to help you understand my problem.
I wanted to develop CustomListView which similar to listview below Inbox in mail app and like that listview I want to make some tools visible when user hover over a ListViewItem like when we hover over a mail in listview of mail app tools like "Delete","Flag","Mark read/unread" become visible and instead of mail subject I want to display content of my itemstemplate.
Now, to do this, I am doing things like that (however, I am not sure if it is correct way or not).
My CustomListView xaml is like this:
<UserControl
x:Class="CustomControls.CustomListView"
xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:CustomControls"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="ListViewItemStyleAllSubjects" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Margin" Value="0,0,18,2"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" ContentMargin="2" ContentTransitions="{TemplateBinding ContentTransitions}" CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" PointerOverBackgroundMargin="1" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" >
<StackPanel Height="100" Width="398" Orientation="Horizontal">
<ContentPresenter Width="318" />
Markup of tools which I want to be visible on hovering over ListViewItem
</StackPanel>
</ListViewItemPresenter>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<ListView x:Name="RootListView"
SelectionMode="Extended"
CanDragItems="True"
SelectionChanged="SelectionChanged"
AllowDrop="True"
DragItemsStarting="RootListView_DragItemsStarting"
Drop="DragDropped"
Header="{Binding Header}"
HeaderTemplate="{Binding HeaderTemplate}"
ItemsPanel="{Binding ItemsPanel}"
Background="{Binding ActualBackground}"
ItemsSource="{Binding ItemsSource}"
Foreground="{Binding ActualForeground}"
BorderThickness="{Binding ActualBorderThickness}"
BorderBrush="{Binding ActualBorderBrush}"
ItemTemplate="{Binding ItemTemplate}"
ItemContainerStyle="{StaticResource ListViewItemStyleAllSubjects}" ContainerContentChanging="ItemsChanged"
>
</ListView>
</UserControl>
As, described earlier the binding on "RootListView" is to expose its properties to user of CustomControl. The datacontext of "RootListView" is set to CustomListView which contains it. (If there is better and easy way, kindly mention it).
(Below paragraph is written assuming that if I set ItemsSource of ListView it will reach to controls defined in itemstemplate of listview in this way ListViewItemPresenter->StackPanel->ContentPresenter->[Controls in itemtemplate applied to listview] and these controls will become children of ContentPresenter in end.)
Since, ControlTemplate can handle hover changes, so I think it would be good to place tools which I want to become visible on hovering in ControlTemplate inside ListViewItemPresenter (as written in above mark up) and if my above assumption is correct then my DataTemplate controls will be visible like mail subject.
I am using this in page as
<Page xmlns="http://ift.tt/w9rHWX;
xmlns:x="http://ift.tt/zZkFEV;
xmlns:local="using:TimeTable_c_sharp"
xmlns:Controls="using:CustomControls"
xmlns:d="http://ift.tt/PuXO1J;
xmlns:mc="http://ift.tt/R4RR6u;
xmlns:ProjectClasses="using:ProjectClasses"
xmlns:UI="using:Microsoft.Advertising.WinRT.UI"
x:Class="TimeTable_c_sharp.MainPage"
mc:Ignorable="d">
<Page.Resources>
<DataTemplate x:Key="AllSubjectsHeaderTemplate">
<Border BorderBrush="#FF677E7B"
BorderThickness="0,0,0,1"
Background="#FF534C4C">
<StackPanel Orientation="Horizontal">
<CheckBox x:Name="checkBox"
HorizontalAlignment="Left"
Margin="10"
VerticalAlignment="Top"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Width="27" />
<TextBlock Grid.Column="1"
TextAlignment="Center"
Text="{Binding Content.Column1, RelativeSource={RelativeSource Mode=TemplatedParent}}"
Margin="22,10,0,0"
TextWrapping="Wrap"
FontStyle="Normal"
FontWeight="Bold"
FontSize="18"
VerticalAlignment="Top"
Width="298"
Height="24"
x:Name="Header1"
Foreground="#FFB2BF8F" />
</StackPanel>
</Border>
</DataTemplate>
<DataTemplate x:Key="AllSubjectsItemTemplate">
<StackPanel Orientation="Horizontal"
d:DesignWidth="434.5">
<CheckBox x:Name="checkBox"
HorizontalAlignment="Left"
Margin="10"
VerticalAlignment="Top"
Controls:CustomListViewCheckChangedCommand.ItemCheckChanged="RandomTextSoEventsGetAttached"
IsChecked="{Binding IsChecked, Mode=TwoWay}"
Width="auto" />
<TextBlock Grid.Column="1"
Text="{Binding SubjectName}"
TextWrapping="WrapWholeWords"
Margin="10"
VerticalAlignment="Top"
Width="350"
Height="auto"
IsTapEnabled="False"
IsRightTapEnabled="False"
IsHoldingEnabled="False"
IsHitTestVisible="False"
IsDoubleTapEnabled="False"
IsColorFontEnabled="True" />
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid Background="#FF271D1D">
<Controls:CustomListView x:Name="allSubjectsList"
Margin="266,141,0,0"
Height="346"
Width="425"
VerticalAlignment="Top"
HorizontalAlignment="Left"
AllowDrop="True"
Header="{Binding AllSubjectsHeader}"
ItemsSource="{Binding AvailibleSubjects}"
BorderBrush="Red"
BorderThickness="10"
ItemTemplate="{StaticResource AllSubjectsItemTemplate}"
HeaderTemplate="{StaticResource AllSubjectsHeaderTemplate}"
ActualBackground="#FF1D2E42"
ActualBorderBrush="#FF575757"
ActualBorderThickness="1"
Visibility="Visible">
</Controls:CustomListView>
</Grid>
</Page>
Here, the datacontext of "allSubjectsList" is set to page containing it.This page has properties "Availible Subjects" which is shown in previous post and "AllSubjectHeader" which just return a string wrapped in a class.
Now, when I run application with this code, nothing is displayed in CustomListView->RootListView except 2 checkboxes (2 because AvailibleSubjects has to items) which are defined in items template,but other controls from itemstemplate are not there.
No comments:
Post a Comment