Related
I'm binding the ICommand nammed GoToSheet to a Button with ControlTemplate.
<Button Margin="10 10 10 10" Command="{Binding GoToSheet}">
<Button.Template>
<ControlTemplate>
<DockPanel Width="840">
<Border DockPanel.Dock="Left" BorderBrush="Black" BorderThickness="5"></Border>
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="2"></Border>
<Border DockPanel.Dock="Right" BorderBrush="Black" BorderThickness="2"></Border>
<Border DockPanel.Dock="Bottom" BorderBrush="Black" BorderThickness="2"></Border>
<DockPanel DockPanel.Dock="Left">
<StackPanel Orientation="Vertical" Margin="20 10 0 10">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical" Margin="0 0 0 10">
<TextBlock Text="{Binding Client}" FontSize="30" FontWeight="Bold" MaxWidth="480"></TextBlock>
<TextBlock Text="{Binding Lieu}" FontSize="22" MaxWidth="480"></TextBlock>
</StackPanel>
<Image Height="35" Width="45" Margin="7 3 0 0" VerticalAlignment="Top" Source="/Resource/Image/CHC.png"></Image>
</StackPanel>
<StackPanel Orientation="Vertical" VerticalAlignment="Bottom" Margin="20 0 0 0">
<TextBlock Text="{Binding MarqueEngin}" FontSize="26" FontWeight="Bold"></TextBlock>
<TextBlock Text="{Binding ModeleEngin}" FontSize="19" FontWeight="Bold"></TextBlock>
</StackPanel>
</StackPanel>
</DockPanel>
<DockPanel DockPanel.Dock="Right" Margin="0 10 20 10">
<TextBlock DockPanel.Dock="Top" Text="{Binding DateIntervention, StringFormat=dd/MM/yyyy}" FontSize="30" HorizontalAlignment="Right"></TextBlock>
<TextBlock DockPanel.Dock="Bottom" Text="{Binding NumeroEngin}" VerticalAlignment="Bottom" FontSize="30" FontWeight="Bold" HorizontalAlignment="Right"></TextBlock>
</DockPanel>
</DockPanel>
</ControlTemplate>
</Button.Template>
</Button>
Why the command only works on the successes areas (see image) ?
Is there a solution for the command works on the entire button area ?
it is caused by lack of background ( button background is NULL).
Please set background for some color, for example:
<Button Margin="10 10 10 10" Background="Transparent" Command="{Binding GoToSheet}">
Here is the solution for similar problem:
Mouse event on transparent background
It should help.
The transparent background must be on the DockPanel in place of Button.
<Button Margin="10 10 10 10" Command="{Binding GoToSheet}">
<Button.Template>
<ControlTemplate>
<DockPanel Width="840" Background="Transparent">
Thanks to macieqqq.
I have a XAML window that the layout is done using a main grid. The problem is when the browser is resized the controls in the second and third columns move to the right and the window's layout is no longer correct. I have pasted the XAML below. I think the layout of a WPF window should be grid based with all controls residing in the window's master grid. Is this the proper layout design for WPF or is there a different recommended layout pattern?
<Window x:Class="MasterPage.Intake1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:MasterPage.View"
Title="Intake 1" Height="900" Width="1000" Background="#FFD9DDE8" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35*"/>
<RowDefinition Height="45*"/>
<RowDefinition Height="190*"/>
<RowDefinition Height="275*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500*"/>
<ColumnDefinition Width="300*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0">
<Image Source="Images\header.jpg" Height="47" Margin="0,0,0,0" />
</StackPanel>
<StackPanel HorizontalAlignment="Left" Grid.Column="0" Height="80" Width="350" Grid.ColumnSpan="1" Grid.Row="1" Margin="0,-23,0,0">
<Image Source="Images\DSPASS_logo.png" Stretch="Fill" DockPanel.Dock="Top" Height="70" />
</StackPanel>
<StackPanel Grid.Column="4" Grid.Row="1" Grid.ColumnSpan="1" Margin="0,0,0,0">
<TextBlock FontSize="15" Margin="0,0,0,0" Height="25" Width="300" TextWrapping="WrapWithOverflow">
<Label FontSize="10" Name="Namelabel" Width="250" FontWeight="Bold" Foreground="#1664A1" Content="Welcome to DS PASS:"/>
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="2" HorizontalAlignment="Left" Margin="10,10,0,0" Height="290" Width="975" VerticalAlignment="Top" Grid.ColumnSpan="3" Grid.RowSpan="1">
<Label Height="36" FontSize="16" Content="Post Identification" Background="#FF014E7E" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_wordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="ApplicantType_TextBlock" Text="Applicant Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_integerWordLength" Orientation="Horizontal" Margin="235,0,200,0">
<TextBlock Height="20" x:Name="textBlockIntegerWordLength" Text="Person Type" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="textBoxIntegerWordLength" Width="400" Margin="10,5"/>
</StackPanel>
<StackPanel x:Name="_Post" Orientation="Horizontal" Margin="235,0,200,20">
<TextBlock Height="20" x:Name="Post_TextBlock" Text="Post" Width="110" Margin="5" TextAlignment="Right"/>
<ComboBox Height="25" x:Name="Post_TextBox" Width="400" Margin="10,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="3" HorizontalAlignment="Left" Height="130" Margin="15,-120,0,0" VerticalAlignment="Top" Grid.ColumnSpan="3" >
<Label Height="36" FontSize="16" Content="Applicant Employment" Background="#FF004A78" FontWeight="Bold" Foreground="White" Margin="-5,0,-18,0"/>
<StackPanel x:Name="_max1" Orientation="Vertical" Margin="1,0,355,0">
<TextBlock Height="20" x:Name="maxTextBlock1" Text="Employee ID" Width="100" Foreground="Black" Margin="0,15,459,5" TextAlignment="Right"/>
<TextBox Height="25" x:Name="maxTextBox1" Width="400" Margin="0,-5,90,25"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="3" Orientation="Vertical" HorizontalAlignment="Left" Height="330" Margin="0,10,0,0" VerticalAlignment="Top" Width="965" Grid.RowSpan="2">
<Label Height="36" FontSize="16" Content="English Version of Name" Background="#FF005183" Grid.Row="4" FontWeight="Bold" Margin="10,10,0,0" Foreground="White" Padding="4,5,5,5"/>
<StackPanel x:Name="_LastName" Orientation="Vertical">
<TextBlock Height="20" x:Name="LastName_TextBlock" Text="Last Name/Surname" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="LastName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_FirstName" Orientation="Vertical">
<TextBlock Height="20" x:Name="FirstName_TextBlock" Text="First Name" Margin="55,0,459,0" TextAlignment="Left"/>
<TextBox Height="25" x:Name="FirstName_TextBox" Width="500" Margin="55,0,459,0"/>
</StackPanel>
<StackPanel x:Name="_MiddleName" Orientation="Vertical">
<TextBlock Height="20" x:Name="MiddleName_TextBlock" Text="Middle Name" Margin="55,5,459,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="MiddleName_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
<StackPanel x:Name="_ExtendedName" Orientation="Vertical">
<TextBlock Height="20" x:Name="ExtendedName_TextBlock" Text="Extended name (Tribal, Jr., III, etc.)" Margin="55,5,372,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Extended_TextBox" Width="500" Margin="55,5,459,5"/>
</StackPanel>
</StackPanel>
<StackPanel Grid.RowSpan="4" Grid.Column="4" HorizontalAlignment="Left" Height="230" Margin="-250,400,0,0" Width="480" Grid.ColumnSpan="1">
<StackPanel x:Name="_Aliases" Orientation="Vertical" Margin="-15,0,0,0" Height="144">
<TextBlock Height="20" x:Name="Aliases_TextBlock" Text="Aliases" Margin="40,-5,0,5" TextAlignment="Left"/>
<TextBox Height="25" x:Name="Aliases_TextBox" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox1" Width="500" Margin="43,5"/>
<TextBox Height="25" x:Name="Aliases_TextBox2" Width="500" Margin="43,5"/>
</StackPanel>
</StackPanel>
<!--<Label HorizontalAlignment="Left" Margin="4,132,0,0" Grid.Row="3" VerticalAlignment="Top" Background="#FF72C772" Grid.ColumnSpan="3" Width="1242" Height="36"/>
<Button Content="Continue" Grid.Column="2" HorizontalAlignment="Left" Margin="16,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125" Click="Page1_Continue_Click"/>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="336,139,0,0" Grid.Row="3" VerticalAlignment="Top" Width="125"/>-->
<Label HorizontalAlignment="Left" Margin="4,400,0,0" Grid.Row="4" VerticalAlignment="Top" Background="#FF52BB52" Grid.ColumnSpan="3" Width="983" Height="36">
</Label>
<Button Content="Save Draft" Grid.Column="1" HorizontalAlignment="Left" Margin="150,408,0,0" Grid.Row="5" VerticalAlignment="Top" Width="125" />
<Button x:Name="ContinueButton_Page2" Content="Continue" Grid.Column="1" Width="125" Grid.Row="5" VerticalAlignment="Top" Margin="200,408,0,0" Grid.ColumnSpan="2" Click="btnContinue_Click"/>
</Grid>
</Window>
When you want control of the alignment during resizing, think Grid. In more complex situations, think Grids inside a Grid. A picture says it better
You have your MainGrid with only rows, no columns. The blue headers get rows of their own and
the orange containers are Grids themselves (with possibly a margin left and right).
Now you shouldn't try to divide the available space with all "...*" width values.
In this example you could use it for dead space only, e.g. the yellow columns with Width="*".
The blue columns would be Width="Auto" (or pixels).
Topping it off with a MinWidth for the Window corresponding with the width you need for the bottom Grid. Also consider wrapping your MainGrid in a ScrollViewer.
What I needed was to not allow resizing of the web browser. To do this I removed the minimize/maximize buttons To do that I used the following attribute:
ResizeMode="NoResize"
I have a long list coming from my Business logic which I need to display on the UI. As the list is long, I tried adding Scrollviewer but I am unable to scroll.
please find the XAML code below
<Grid Margin="0,32,0,0">
<TextBlock Text="{Binding IDC_WiFi, Source={StaticResource Resources}}" FontFamily="Segoe UI" FontSize="20" Foreground="#4cb5ab" HorizontalAlignment="Left" />
<Button Command="{Binding HardwareWifiAccordionCommand}" BorderThickness="0" Width="16" HorizontalAlignment="Right" Height="16" >
<Button.Background>
<ImageBrush ImageSource="{Binding AccordionImageHardwareWifi}" />
</Button.Background>
</Button>
</Grid>
<TextBlock Text="Klein's, Anil's" FontFamily="Segoe UI" FontSize="15" Foreground="#8fa3ad"/>
<StackPanel Height="200" Visibility="{Binding IsAccordionHardwareWifi, Converter={StaticResource Bool2Visible}}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding WifiList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,32,0,0">
<Grid>
<Image Source="/Images/Assets/da_wifi1_16x16.png" Height="16" Width="16" HorizontalAlignment="Left" />
<TextBlock Margin="25,0,0,0" Text="{Binding NetworkName}" FontSize="15" Foreground="#FFFFFF" />
<TextBlock Text="" FontSize="15" Foreground="#8fa3ad" HorizontalAlignment="Right" />
</Grid>
<TextBlock Text="" FontSize="15" Foreground="#8fa3ad" HorizontalAlignment="Left" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</StackPanel>
Put it into a ScrollViewer.
<ScrollViewer>
<StackPanel >
</StackPanel>
</ScrollViewer>
As #StepUp points out you can just wrap it with a ScrollViewer but I believe this breaks virtualization. That's outside the scope of this question of course but it's something to keep in mind. If performance is likely to become an issue then I'd suggest implementing this as shown in the answer to this question.
The scrollviewer needed a Height to be set
<Grid Margin="0,32,0,0">
<TextBlock Text="{Binding IDC_WiFi, Source={StaticResource Resources}}" FontFamily="Segoe UI" FontSize="20" Foreground="#4cb5ab" HorizontalAlignment="Left" />
<Button Command="{Binding HardwareWifiAccordionCommand}" BorderThickness="0" Width="16" HorizontalAlignment="Right" Height="16" >
<Button.Background>
<ImageBrush ImageSource="{Binding AccordionImageHardwareWifi}" />
</Button.Background>
</Button>
</Grid>
<TextBlock Text="Klein's, Anil's" FontFamily="Segoe UI" FontSize="15" Foreground="#8fa3ad"/>
<StackPanel Height="200" Visibility="{Binding IsAccordionHardwareWifi, Converter={StaticResource Bool2Visible}}">
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="350">
<ItemsControl ItemsSource="{Binding WifiList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,32,0,0">
<Grid>
<Image Source="/Images/Assets/da_wifi1_16x16.png" Height="16" Width="16" HorizontalAlignment="Left" />
<TextBlock Margin="25,0,0,0" Text="{Binding NetworkName}" FontSize="15" Foreground="#FFFFFF" />
<TextBlock Text="" FontSize="15" Foreground="#8fa3ad" HorizontalAlignment="Right" />
</Grid>
<TextBlock Text="" FontSize="15" Foreground="#8fa3ad" HorizontalAlignment="Left" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</StackPanel>
My List View contains nearly 10 items.I am able to show vertical scroll bar for list view. I am able to scroll the items by clicking on vertical scroll bar.
But What I want is When User placed control over a List View and trying to scroll the Items with Mouse that I am unable to do.
Please help me how can I solve this Issue.
Please give me your valuable Suggestions.
Here I am Adding My List View Code
<Border BorderThickness="0.5" CornerRadius="2" BorderBrush="Gray" Width="1250" Height="730" Margin="0,5,0,0">
<StackPanel Name="spStore" Visibility="Hidden" Background="AliceBlue">
<Label Content="{DynamicResource keyStore Management}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="DarkTurquoise"/>
<!--Scroll view to display list of items-->
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="690" Visibility="Visible">
<StackPanel Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="{DynamicResource keySTOCK MANAGEMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="0"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="1" ScrollViewer.CanContentScroll="True" Name="lvstock" PreviewMouseWheel="lvstock_PreviewMouseWheel">
<ListViewItem MouseLeftButtonUp="StockDetails_Click" Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Critical.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyView Stocks}" ></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockVerificationDetails_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerify Stocks}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="VerifiedStockDetails_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerified Stock Report}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyGOODS TRANSFER}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="2"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="3">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockReceipt_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Receipt}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockIssue_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsIssue.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Issue}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" Name="GoodsReturn" BorderThickness="0.5,0.5,0.5,0" MouseLeftButtonUp="GoodsReturn_MouseLeftButtonUp" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyGoodsReturn}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyGOODS PROCUREMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="4"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="5">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/PO.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyPurchases}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="ProcurementReceipt_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyReceipts}"></TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
<Label Content="{DynamicResource keyDELIVERIES}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="6"></Label>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="7">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/NewOrder.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyOrders}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyShipments}">Shipments</TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Border>
Thanks in advance.
The main problem with your XAML code is that MouseWheel event is handled by each inner ListView inside main ScrollViewer.
It's correct behavior in case when inner ListViews have theirs inner scrollbars (to prevent double scrolling - scrolling of inner scrollbar and scrolling of outer scrollbar).
As scrolling is not intended in inner ListViews, you can just assign special non scrollable Template for each inner ListView as presented in the following example:
Define the template for ListView in resources:
<Window.Resources>
<ControlTemplate x:Key="NonScrollableListView" TargetType="ListView">
<ItemsPresenter/>
</ControlTemplate>
</Window.Resources>
Then use it for each ListView inside the main ScrollViewier:
<ScrollViewer>
<StackPanel Orientation="Vertical">
<Grid>
<Grid.RowDefinitions>
<!--...-->
</Grid.RowDefinitions>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="1" Name="lvstock">
<!--...-->
</ListView>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="3">
<!--...-->
</ListView>
<!--...-->
<ListView Template="{StaticResource NonScrollableListView}" Margin="0" Background="White" BorderThickness="0" Grid.Row="5">
<!--...-->
</ListView>
</Grid>
</StackPanel>
</ScrollViewer>
you should change DragOver event for the ListView as follows:
private void ListView_DragOver(object sender, System.Windows.DragEventArgs e)
{
var lv = sender as ListView;
ScrollViewer sv = FindVisualChild<ScrollViewer>(lv);
double tolerance = 10;
double verticalPos = e.GetPosition(lv).Y;
double offset = 3;
if (verticalPos < tolerance)
{
sv.ScrollToVerticalOffset(sv.VerticalOffset - offset);
}
else if (verticalPos > lv.ActualHeight - tolerance)
{
sv.ScrollToVerticalOffset(sv.VerticalOffset + offset);
}
}
public static childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject
{
// Search immediate children first (breadth-first)
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else
{
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
After trying with many example I have found the solution and its working fine for me. What I observed is Inside Stack Panel scroll is not working but in Grid its working and instead of taking multiple list views I have Used only single List View. Thank you all for giving your valuable suggestions.
Here I am placing My working Code ... Once again Thank you guys for your suggestions.
<Grid Name="spStore" Visibility="Hidden" Background="AliceBlue">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Label Content="{DynamicResource keyStore Management}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Grid.Row="0" Foreground="DarkTurquoise"/>
<ListView Margin="0" Background="White" BorderThickness="0" Grid.Row="1" Name="lvstock">
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keySTOCK MANAGEMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem MouseLeftButtonUp="StockDetails_Click" Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Critical.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyView Stocks}" ></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockVerificationDetails_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerify Stocks}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="VerifiedStockDetails_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/StockVerification.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyVerified Stock Report}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyGOODS TRANSFER}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockReceipt_Click" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Receipt}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="StockIssue_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsIssue.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyStock Issue}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" Name="GoodsReturn" BorderThickness="0.5,0.5,0.5,0" MouseLeftButtonUp="GoodsReturn_MouseLeftButtonUp" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyGoodsReturn}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyGOODS PROCUREMENT}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/PO.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyPurchases}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" MouseLeftButtonUp="ProcurementReceipt_Click" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/GoodsReceipts.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyReceipts}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Label Content="{DynamicResource keyDELIVERIES}" Foreground="DarkTurquoise" FontSize="18" FontWeight="Bold" HorizontalAlignment="Left"></Label>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/NewOrder.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyOrders}"></TextBlock>
</StackPanel>
</ListViewItem>
<ListViewItem Background="AliceBlue" BorderBrush="Gray" BorderThickness="0.5,0.5,0.5,0.5" Cursor="Hand">
<StackPanel Orientation="Horizontal">
<Image Source="Images/shipment_icon.png" Margin="0,0,5,0" Height="80" Width="80" />
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="15" Text="{DynamicResource keyShipments}">Shipments</TextBlock>
</StackPanel>
</ListViewItem>
</ListView>
</Grid>
ListView in ScrollViewer did not work for me, it helped to remove the ScrollViewer and set the scrollviewer.verticalscrollbarvisibility = true property of the ListView
I tried to implement case in which one TextBlock appears on top of another TextBlock, playing with Visibility property - but it doesn't working yet.
TextBlock are inside DockPanel:
<DockPanel Grid.Row="1" Margin="5">
<TextBlock Text="Text1" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right">
<TextBlock Text="Text2" Background="Aqua" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource ResourceKey=BoolToVisibilityConverter}}" />
</TextBlock>
<TextBlock Text="#Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
</DockPanel>
You will want to use a Grid to group these TextBlocks, DockPanel/StackPanel will not allow overlapping controls(without horrible manipulation of Margins etc)
<DockPanel Grid.Row="1" Margin="5" >
<Grid DockPanel.Dock="Right" >
<TextBlock Text="Text1" />
<TextBlock Text="Text2" Background="Aqua" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource ResourceKey=BoolToVisibilityConverter}}" />
</Grid>
<TextBlock Text="#Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
</DockPanel>