FlowDocument from XAML is not Responsive when Printing - c#

The problem is that when I print the FlowDocument, it prints the same as what the Window is showing, and not the FlowDocument itself.
Here's the XAML:
<Window x:Class="POS.DailySalesReport"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:POS"
mc:Ignorable="d"
Height="500"
Width="816"
Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen">
<Grid>
<FlowDocumentPageViewer x:Name="flwView">
<FlowDocument x:Name="flwDoc"
TextAlignment="Center"
ColumnWidth="{Binding ElementName=flwView, Path=ActualWidth}">
<BlockUIContainer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid x:Name="grdDetails"
Grid.Row="0"
Grid.Column="0"
Margin="0,0,0,30">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Ellipse Grid.Row="0"
Grid.Column="0"
Height="90"
Width="90"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Ellipse.Fill>
<ImageBrush x:Name="imgUser" />
</Ellipse.Fill>
</Ellipse>
<Grid Grid.Row="0"
Grid.Column="1"
Margin="10, 0, 0, 0">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="lblCompanyName"
Grid.Row="0"
Grid.Column="0"
Text="COMPANY NAME"
FontFamily="{StaticResource RobotoRegular}"
FontSize="18"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBlock x:Name="lblCompanyAddress"
Grid.Row="1"
Grid.Column="0"
Text="Business Address"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBlock x:Name="lblCompanyNumber"
Grid.Row="2"
Grid.Column="0"
Text="Contact Number"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
<TextBlock x:Name="lblCompanyTIN"
Grid.Row="3"
Grid.Column="0"
Text="TIN Number"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
</Grid>
<StackPanel Grid.Row="0"
Grid.Column="2">
<TextBlock x:Name="lblReportType"
FontFamily="{StaticResource RobotoBold}"
FontSize="12"
HorizontalAlignment="Right" />
<TextBlock x:Name="lblReportDate"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
HorizontalAlignment="Right" />
</StackPanel>
</Grid>
<ListView x:Name="lstView"
Grid.Row="1"
Grid.Column="0"
BorderThickness="0"
SelectionMode="Single"
Width="{Binding ElementName=flwDoc, Path=ActualWidth}">
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="White" />
</Setter.Value>
</Setter>
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="Black" />
</Setter.Value>
</Setter>
<Setter Property="FontSize"
Value="11" />
<Setter Property="FontFamily"
Value="{StaticResource RobotoMedium}" />
<Setter Property="Height"
Value="35" />
<Setter Property="BorderThickness"
Value="0, 1, 0, 1" />
<Setter Property="BorderBrush">
<Setter.Value>
<SolidColorBrush Color="Black" />
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListView}">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="White" />
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListViewItem}">
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="Black"
Opacity="0.8" />
</Setter.Value>
</Setter>
<Setter Property="FontFamily"
Value="{StaticResource RobotoMedium}" />
<Setter Property="FontSize"
Value="17" />
<Setter Property="Background"
Value="White" />
<Setter Property="Padding"
Value="0, 10, 0, 10" />
<Setter Property="Margin"
Value="0, 0, 0, 10" />
<Style.Resources>
<!-- Foreground for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black"
Opacity="0.8" />
<!-- Background for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="White" />
<!-- Foreground for Inactive Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
Color="Black"
Opacity="0.8" />
<!-- Background for Inactive Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="White" />
</Style.Resources>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn x:Name="lstHeader1"
Header="Description">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ProductDescription}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lstHeader2"
Header="Supplier">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Supplier}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lstHeader3"
Header="Sold">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ProductSold}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lstHeader4"
Header="Cost Price">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ProductCost}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lstHeader5"
Header="Retail Price">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ProductRetail}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lstHeader6"
Header="Total(Qty * Retail Price)">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding TotalRetail}"
TextAlignment="Center"
FontFamily="{StaticResource RobotoRegular}"
FontSize="12"
TextWrapping="Wrap" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<Grid Grid.Row="2"
Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0"
Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="Total Items Sold"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoBold}" />
<TextBlock x:Name="lblTotalSold"
Grid.Row="0"
Grid.Column="1"
Text="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoRegular}" />
<TextBlock Grid.Row="1"
Grid.Column="0"
Text="Total Cost Amount"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoBold}" />
<TextBlock x:Name="lblTotalCost"
Grid.Row="1"
Grid.Column="1"
Text="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoRegular}" />
<TextBlock Grid.Row="2"
Grid.Column="0"
Text="Total Retail Amount"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoBold}" />
<TextBlock x:Name="lblTotalRetail"
Grid.Row="2"
Grid.Column="1"
Text="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoRegular}" />
<TextBlock Grid.Row="3"
Grid.Column="0"
Text="Profit"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoBold}" />
<TextBlock x:Name="lblProfit"
Grid.Row="3"
Grid.Column="1"
Text="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="10"
FontFamily="{StaticResource RobotoRegular}" />
</Grid>
</Grid>
</Grid>
</BlockUIContainer>
</FlowDocument>
</FlowDocumentPageViewer>
</Grid>
</Window>
Overall, the items in the ListView is dynamic. The problem appears when the list became longer than the height of the Window, ruining the appearance of the report (like the ellipse), and it is the same as the printed version.
Here's the code-behind:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
PrintDialog printDlg = new PrintDialog();
var actualWidth = lstView.ActualWidth - 10;
lstHeader1.Width = actualWidth / 6;
lstHeader2.Width = actualWidth / 6;
lstHeader3.Width = actualWidth / 6;
lstHeader4.Width = actualWidth / 6;
lstHeader5.Width = actualWidth / 6;
lstHeader6.Width = actualWidth / 6;
PopulateListView(ChosenDate);
string businessName = "";
string businessAddress = "";
string businessTIN = "";
string businessContact = "";
string businessImage = "";
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
string query = "SELECT * FROM dbo.Company";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
try
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
businessName = reader["Name"].ToString();
businessAddress = reader["Address"].ToString();
businessTIN = reader["TIN"].ToString();
businessContact = reader["Contact"].ToString();
businessImage = reader["ImagePath"].ToString();
}
}
}
}
catch (Exception err)
{
MessageBox.Show(err.Message + err.StackTrace);
}
}
}
BitmapImage img;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + businessImage))
{
img = new BitmapImage();
img.BeginInit();
img.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.CacheOption = BitmapCacheOption.OnLoad;
img.UriSource = new Uri(AppDomain.CurrentDomain.BaseDirectory + businessImage);
img.EndInit();
}
else
{
img = new BitmapImage(new Uri("pack://application:,,,/Resources/default_product_img.png"));
}
imgUser.ImageSource = img;
lblCompanyName.Text = businessName;
lblCompanyAddress.Text = businessAddress;
lblCompanyTIN.Text = businessTIN;
lblCompanyNumber.Text = businessContact;
lblReportType.Text = ReportType;
lblReportDate.Text = ChosenDate.ToString("MM/dd/yyyy");
lblTotalSold.Text = TotalSold.ToString();
lblTotalCost.Text = TotalCost.ToString("F2");
lblTotalRetail.Text = TotalRetail.ToString("F2");
lblProfit.Text = TotalProfit.ToString("F2");
IDocumentPaginatorSource idpSource = flwDoc;
var result = printDlg.ShowDialog();
if (result == true)
{
printDlg.PrintDocument(idpSource.DocumentPaginator, "Document");
}
}
I thought that the UI appearing in the Window is just for visual display, and not really what the PrintDialog prints, but the FlowDocument itself. If it is not possible, I'm planning to re-create the controls in code-behind just to maintain responsiveness. So I'm asking here first if there is a fix for this.

Related

WPF Does not display vertical scrollbar

i am trying to create an application that will display user controls, based on information collected from DB. The problem is that if items total height exceeds mainwindow grid reserved for this display, i do not see a vertical scrollbar. From what i had found there might be an issue, that stackpanel/scrollviewer does not limit size of it's children. Im stuck on how to solve this, is there any way to stack items in limited spaces with scrollbar visible only when needed.
I want to avoid "hardcoding" the height of scrollviewer.
For now i'm stuck with below code:
XAML: (main window)
<Grid Name="selectedOptionGrid"
Grid.Column="1"
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<StackPanel Name="selectedOptionStack"/>
<!-- Dock selected windows based on option selected-->
</Grid>
(user control, additional window docked to mainwindow)
<UserControl x:Class="Power_Planner_1._0.Team_Planner.MyTasks.ucTaskWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Power_Planner_1._0.Team_Planner.MyTasks"
mc:Ignorable="d">
<Grid Background="White"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="5"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Orientation="Horizontal"
VerticalAlignment="Top"
Margin="0,5,0,0">
<TextBlock Margin="60,0,0,0" Width="160" FontWeight="Bold">Task Name</TextBlock>
<TextBlock Margin="10,0,0,0" Width="160" FontWeight="Bold">Team Name</TextBlock>
<TextBlock Margin="0,0,0,0" Width="55" FontWeight="Bold">Deadline</TextBlock>
<TextBlock Margin="20,0,0,0" Width="60" FontWeight="Bold">Start</TextBlock>
<TextBlock Margin="28,0,0,0" Width="60" FontWeight="Bold">End</TextBlock>
<TextBlock Margin="20,0,0,0" Width="60" FontWeight="Bold">Run Time</TextBlock>
</StackPanel>
<Separator Grid.Row="1"
VerticalAlignment="Top"/>
<Grid Name="taskListGrid"
Grid.Row="2"
Height="510"
Width="830">
<ScrollViewer VerticalScrollBarVisibility="Auto"
Width="{Binding ActualWidth,RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Grid}}"
Height="{Binding ActualHeight,RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Grid}}">
<StackPanel Orientation="Vertical"
x:Name="taskListStack">
<StackPanel.Resources>
<Style TargetType="UserControl">
<Setter Property="Margin" Value="0,5,0,0"/>
</Style>
</StackPanel.Resources>
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
</UserControl>
And finally an Items that are created:
<UserControl x:Class="Power_Planner_1._0.Team_Planner.MyTasks.ucTaskItem"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Power_Planner_1._0.Team_Planner.MyTasks"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" d:DesignHeight="45">
<Border CornerRadius="12,12,12,12"
BorderThickness="1,1,1,1"
BorderBrush="LightGray"
Background="#FF456780"
Padding="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="160"/>
<ColumnDefinition Width="65"/>
<ColumnDefinition Width="90"/>
<ColumnDefinition Width="90"/>
<ColumnDefinition Width="65"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Picture-->
<Border Grid.Column="0"
CornerRadius="25,25,25,25"
BorderThickness="1,1,1,1"
Width="30"
Height="30"
BorderBrush="LightGray"
Background="ForestGreen"
HorizontalAlignment="Left"
Margin="10,0,0,0">
</Border>
<!--Task Name-->
<TextBlock Grid.Column="1"
Margin="10,0,0,0"
FontSize="12"
Foreground="LightGray"
Text="{Binding taskName}"
Width="160"
VerticalAlignment="Center">
</TextBlock>
<!--Team Name-->
<TextBlock Grid.Column="2"
Margin="20,0,0,0"
FontSize="12"
Foreground="LightGray"
Text="{Binding teamName}"
Width="160"
VerticalAlignment="Center">
</TextBlock>
<!--Deadline-->
<TextBlock Grid.Column="3"
Margin="20,0,0,0"
FontSize="12"
Foreground="LightGray"
Text="{Binding deadline}"
Width="45"
VerticalAlignment="Center">
</TextBlock>
<!--Start-->
<Button Grid.Column="4"
Background="#FF456780"
BorderBrush="LightGray"
Height="25"
Margin="20,0,0,0"
Width="60">
<Button.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Button.Resources>
<TextBlock Foreground="LightGray">Start</TextBlock>
</Button>
<!--Stop-->
<Button Grid.Column="5"
Background="#FF456780"
BorderBrush="LightGray"
Height="25"
Margin="20,0,0,0"
Width="60">
<Button.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Button.Resources>
<TextBlock Foreground="LightGray">Stop</TextBlock>
</Button>
<!--Deadline-->
<TextBlock Grid.Column="6"
Margin="20,0,0,0"
FontSize="12"
Foreground="LightGray"
Text="{Binding runtime}"
Width="45"
VerticalAlignment="Center">
</TextBlock>
<!--Other Options-->
<materialDesign:PopupBox Grid.Column="7"
StaysOpen="False"
Foreground="White"
HorizontalAlignment="Right">
<StackPanel Width="150"
Background="White">
<Button Content="Edit"/>
<Button Content="View Details"/>
<Button Content="Comment"/>
</StackPanel>
</materialDesign:PopupBox>
</Grid>
</Border>
</UserControl>
Code to add items:
taskListStack.Children.Clear();
var task1 = new clsTaskItem("Test1", "blablabla", "12:40", "02:30");
taskListStack.Children.Add(new ucTaskItem(task1));
var task2 = new clsTaskItem("Test2", "blablabla", "13:45");
taskListStack.Children.Add(new ucTaskItem(task2));
var task3 = new clsTaskItem("Test3", "blablabla", "11:45");
taskListStack.Children.Add(new ucTaskItem(task3));
var task4 = new clsTaskItem("Test4", "blablabla", "14:45");
taskListStack.Children.Add(new ucTaskItem(task4));
var task5 = new clsTaskItem("Test5", "blablabla", "17:45");
taskListStack.Children.Add(new ucTaskItem(task5));
var task6 = new clsTaskItem("Test6", "blablabla", "18:45");
taskListStack.Children.Add(new ucTaskItem(task6));
var task7 = new clsTaskItem("Test7", "blablabla", "13:23");
taskListStack.Children.Add(new ucTaskItem(task7));
var task8 = new clsTaskItem("Test8", "blablabla", "12:54");
taskListStack.Children.Add(new ucTaskItem(task8));
var task9 = new clsTaskItem("Test9", "blablabla", "17:23");
taskListStack.Children.Add(new ucTaskItem(task9));
var task10 = new clsTaskItem("Test10", "blablabla", "17:10");
taskListStack.Children.Add(new ucTaskItem(task10));
taskListStack.Children.Add(new ucTaskItem(task1));
taskListStack.Children.Add(new ucTaskItem(task2));
taskListStack.Children.Add(new ucTaskItem(task3));
taskListStack.Children.Add(new ucTaskItem(task4));
taskListStack.Children.Add(new ucTaskItem(task5));
taskListStack.Children.Add(new ucTaskItem(task6));
taskListStack.Children.Add(new ucTaskItem(task7));
taskListStack.Children.Add(new ucTaskItem(task8));
taskListStack.Children.Add(new ucTaskItem(task9));
taskListStack.Children.Add(new ucTaskItem(task10));
And task item class ( to which items are binded via datacontext)
public class clsTaskItem
{
public clsTaskItem(string tsname, string tmname, string dline, string rtime = "00:00:00")
{
taskName = tsname;
teamName = tmname;
deadline = dline;
runtime = rtime;
}
public string taskName { get; private set; }
public string teamName { get; private set; }
public string deadline { get; private set; }
public string runtime { get; private set; }
}
As you can see i had tried to bind the scrollviewer height to grid i had created on top of it, thinking that if i set height to auto, it will get the height from the grid actual height. Well that didn't make much sense hence it was not working. I'm trying to find another solution for grouping the items, that way that i could expand easily main window, without coding each window to expand with this expansion so that items would both fill all available space and display scrollbar when needed.
Please help :)

C# WPF Dynamic List with Binding

I need to make a list , example : List
I get datas from SQL, it's possible to scroll if there are more datas.
I need to create this list in WPF.
I need to click on label 00000-0 or label "A" or "F".
I try this :
<ListView x:Name="lvDataBinding" HorizontalContentAlignment="Stretch" BorderThickness="0" Margin="10" Grid.Row="3" Background="{x:Null}" ItemsSource="{Binding}" Foreground="White">
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type local:CL_Operation}">
<Border BorderBrush="White" BorderThickness="0" CornerRadius="3" Margin="0,3" Grid.ColumnSpan="4" Background="Transparent">
<Border.Effect>
<DropShadowEffect BlurRadius="5" ShadowDepth="5" />
</Border.Effect>
<Grid Background="Transparent" Margin="0,1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="1.5*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical" Margin="50,5" >
<!-- <TextBlock Text="Customer" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strPriorite}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="1">
<!-- <TextBlock Text="Location" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strRetardAvanceText}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="2">
<!-- <TextBlock Text="Created On" Foreground="#33B6EF" FontSize="20" />-->
<TextBlock Text="{Binding strNoOfOp}" FontSize="20" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Column="3">
<!-- <TextBlock Text="Quantity" Foreground="#33B6EF" FontSize="20" /> -->
<TextBlock Text="{Binding strDescriptionOp}" FontSize="20" />
</StackPanel>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Window.Resources>
<DataTemplate DataType="{x:Type local:CL_Operation}" >
<Border BorderThickness = "1" BorderBrush = "Green" Margin = "2" Padding = "5" Width = "900" CornerRadius = "3" >
<Grid >
<Grid.ColumnDefinitions >
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions >
<TextBlock Grid.Column = "0" Text = "{Binding Path = strRetardAvanceText}" Background = "LightBlue" />
<!-- <TextBlock Grid.Column = "0" Text = "{Binding Path = strNoOfOp}" Background = "LightBlue" />-->
<TextBlock Grid.Column = "1" Text = "{Binding Path = strDescriptionOp}" Background = "LightBlue" />
<TextBlock Grid.Column = "2" Text = "{Binding Path = strNoArticle}" FontStyle = "Italic" />
</Grid >
</Border >
<DataTemplate.Triggers >
<DataTrigger Binding = "{Binding Path = strRetardAvanceText}" Value = "26 jrs" >
<Setter Property = "ListBoxItem.Foreground" Value = "Red" ></Setter >
</DataTrigger >
</DataTemplate.Triggers >
</DataTemplate >
</Window.Resources >
<Grid >
<ListBox x:Name = "listBox1" ItemsSource = "{Binding}" />
</Grid >
It's a good result but not on two columns, it's a lot of different
Thank you for your help.

Scrolling to active tabcontrol header in stackpanel in WPF

With the following code I can create a non wrapped scrolling stackpanel of headers of a tabcontrol. It has repeat buttons that can control the scroll. I would like instead for the repeat buttons to be able to control which tab is active, and adjust the scroll so the active tab can scroll into view. Is such a thing possible?
<TabControl SelectedItem="{Binding ActiveTicketFilterTab, Mode=TwoWay}"
Margin="5"
Grid.Row="1"
BorderBrush="Gray"
BorderThickness="2"
Style="{StaticResource ResourceKey=somestyle}"
SelectionChanged="selectionchanged"
Name="somename"
Background="#252525"
ItemsSource="{Binding someobslist}"
Grid.ColumnSpan="2">
<TabControl.Resources>
<Style x:Key="TabScrollerRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Background="sc#1, 0.366693377, 0.372125238, 0.6931424">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding ContentControl.Content}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabControl.Template>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
<RowDefinition x:Name="RowDefinition1" Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer Panel.ZIndex="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<ScrollViewer.Style>
<Style TargetType="{x:Type ScrollViewer}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Margin="0,0,0,0" Grid.Row="0" Grid.Column="0" x:Name="HeaderPanel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ScrollContentPresenter Grid.Column="0" Content="{TemplateBinding ScrollViewer.Content}" />
<StackPanel Orientation="Horizontal" Grid.Column="1">
<RepeatButton Style="{StaticResource TabScrollerRepeatButtonStyle}" Content="<" Command="ScrollBar.LineLeftCommand"/>
<RepeatButton Style="{StaticResource TabScrollerRepeatButtonStyle}" Content=">" Command="ScrollBar.LineRightCommand"/>
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ScrollViewer.Style>
<StackPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" Orientation="Horizontal"/>
</ScrollViewer>
<Border x:Name="ContentPanel"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Grid.Row="1"
Grid.Column="0"
Margin="2,-2, 0, 13"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2"
KeyboardNavigation.TabNavigation="Local">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</Grid>
</ControlTemplate>
</TabControl.Template>
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem" BasedOn="{StaticResource someotherstyle}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Border BorderBrush="{x:Null}" Height="25">
<TextBlock Padding="10" Name="Title" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" HorizontalAlignment="Stretch" Text="{Binding Name}" ToolTip="{Binding Name}" />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
<TabControl.ContentTemplate>
<DataTemplate>
<Grid Background="Transparent">
<ListBox x:Name="ticketView"
Unloaded="On_Listbox_enter"
ItemsSource="{Binding TicketsView}"
Background="#252525"
Margin="5,5,0,0"
HorizontalContentAlignment="Stretch"
BorderBrush="{x:Null}"
BorderThickness="1"
Padding="0,0,5,0"
VirtualizingPanel.IsVirtualizing="False"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="False"
ItemTemplate="{StaticResource TicketViewTemplate}">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#252525" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />
</ListBox.Resources>
</ListBox>
<StackPanel Grid.Row="0" Margin="328,75"
Visibility="{Binding ExposeTicketSpinner, Converter={StaticResource BoolToVisConverter}}"
Width="Auto">
<Viewbox Grid.Row="0"
Height="100"
Width="100"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<WPFControls:CircularProgressBar HorizontalAlignment="Center" VerticalAlignment="Center" />
</Viewbox>
<Label Foreground="White" FontWeight="Bold" Margin="0,33" Content="Loading Tickets..." HorizontalAlignment="Center"></Label>
</StackPanel>
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
To get your things to work as desired, do the following:
First
Replace your Repeatbuttons with this
<RepeatButton Style="{StaticResource TabScrollerRepeatButtonStyle}" Content="<" Command="{Binding MoveLeftCommand}"/>
<RepeatButton Style="{StaticResource TabScrollerRepeatButtonStyle}" Content=">" Command="{Binding MoveRightCommand}"/>
Second
In your ViewModel (That holds the TabControl) do it like this:
public ICommand MoveLeftCommand => new RelayCommand(x => {
var currIdx = this.someobslist.IndexOf(this.ActiveTicketFilterTab);
this.ActiveTicketFilterTab = currIdx == 0 ? this.someobslist[this.someobslist.Count - 1] : this.someobslist[currIdx - 1];
});
public ICommand MoveRightCommand => new RelayCommand(x => {
var currIdx = this.someobslist.IndexOf(this.ActiveTicketFilterTab);
this.ActiveTicketFilterTab = currIdx == this.someobslist.Count - 1 ? this.someobslist[0] : this.someobslist[currIdx + 1];
});
Thats it. In case you need a RelayCommand, i can hand you mine. Of course replace my Varaibles with yours.
This Solution circles now through the TabItems
EDIT
Here is a plain scrollcycler without navigating to the TabItem, based on this <--- IMPORTANT
Add to your ScrollViewer a Loaded-Event in XAML
Here the code:
private int _scollMoverIdx = 0;
private TabControl _container;
private void ScrollViewer_OnLoaded(object sender, RoutedEventArgs e) {
this._container = (sender as ScrollViewer).TemplatedParent as TabControl;
}
public ICommand MoveLeftCommand => new RelayCommand(x => {
if (this._scollMoverIdx == 0) {
this._scollMoverIdx = this.someobslist.Count - 1;
this._container.ScrollToCenterOfView(this.someobslist[_scollMoverIdx]);
} else {
_scollMoverIdx--;
this._container.ScrollToCenterOfView(this.someobslist[_scollMoverIdx]);
}
});
public ICommand MoveRightCommand => new RelayCommand(x => {
if (this._scollMoverIdx == this.someobslist.Count - 1) {
this._scollMoverIdx = 0;
this._container.ScrollToCenterOfView(this.someobslist[_scollMoverIdx]);
} else {
_scollMoverIdx++;
this._container.ScrollToCenterOfView(this.someobslist[_scollMoverIdx]);
}
});
Its not really pretty, but i wanted to keep it simple. The linked Extension method is greate for reusability (Credits to Ray Burns). If you want this to be MVVM-conform, i suggest making a CustomControl, since scrolling from ViewModel is breaking the pattern.
Cheers

how to get listboxitem's value on listbox hold event?

xmal code:
<ListBox x:Name="listbox2" Margin="0,0" SelectionChanged="listbox2_SelectionChanged" Hold="listbox2_Hold" >
<ListBox.ItemContainerStyle >
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="0,0,0,1" BorderBrush="Gray">
<Grid Width="auto" HorizontalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" FontSize="40" Grid.Column="1" Grid.Row="0" Foreground="White" Text="{Binding NAME}"></TextBlock>
<TextBlock VerticalAlignment="Center" FontSize="25" Grid.Column="1" Grid.Row="1" Foreground="Blue" Text="{Binding PHONE}"></TextBlock>
<Image Name="c1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="100" Stretch="Fill" Margin="0" Source="{Binding IMGS}" Grid.RowSpan="2" Grid.Column="0" />
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
class list which is bind to list box is
List < contactsclass > contacts = new List < contactsclass >();
PHONE and NAME are getter setter of the contactclass's variables
how can i get this variable's value on hold event of listbox .. i am trying following code
private void listbox2_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
//contextmenucontact = (contactsclass)(sender as ListBox).DataContext;
contextmenucontact = (contactsclass)listbox2.SelectedItem;
MessageBox.Show(contextmenucontact.name);
}
if is just the selected item is just use the ToString Function, see this:
if (listBox1.SelectedItem != null)
{
string itemText = listBox1.SelectedItem.ToString();
contextmenucontact = new contactsclass();
contextmenucontact.name = itemText;
MessageBox.Show(contextmenucontact.name);
}

Filter on Silverlight Datagrid using Radio Buttons C#

I have a datagrid:
<Grid x:Name="MainDataGrid" Grid.Row="5" >
<data:DataGrid x:Name="datagrid" AutoGenerateColumns="False" HorizontalAlignment="Stretch" IsReadOnly="True" VerticalAlignment="Top" ItemsSource="{Binding DataList}" Height="220" Margin="5">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="#" Binding="{Binding Number}" />
<data:DataGridTextColumn Header="Business Process" Width="300" Binding="{Binding BusinessProcess}" />
<data:DataGridTextColumn Header="Sub Process" Width="300" Binding="{Binding SubProcess}" />
<data:DataGridTextColumn Header="ITAC" Width="100" Binding="{Binding Itac}" />
<data:DataGridTextColumn Header="Status" Width="200" Binding="{Binding Status}" />
</data:DataGrid.Columns>
</data:DataGrid>
</Grid>
Which is currently bound to some dummy data I created in the ViewModel:
public class ItacViewModel : ViewModelBase
{
public List<data> DataList { get; set; }
public ItacViewModel()
{
var dataList = new List<data>
{
new data(1, "Fixed Asset", "Depreciation", "UL-AC1", "Under Review"),
new data(2, "Fixed Asset", "Depreciation", "UL-AC2", "Complete"),
new data(3, "Order to Cash", "Invoicing", "UL-AC3", "Under Review"),
new data(4, "Order to Cash", "Shipping Goods", "UL-AC4", "Under Review"),
new data(5, "Order to Cash", "Depreciation", "UL-AC5", "Complete"),
new data(6, "Order to Cash", "Depreciation", "UL-AC6", "Under Review"),
new data(7, "Order to Cash", "Depreciation", "UL-AC7", "Complete"),
new data(8, "Stock and Make", "Depreciation", "UL-AC8", "Under Review"),
new data(9, "Stock and Make", "Depreciation", "UL-AC9", "Under Review"),
new data(10, "General Accounting & Reporting", "Depreciation", "UL-AC10", "Complete")
};
DataList = dataList;
}
}
I wish to be able to filter the data when a Radio Button is selected (The Radio Button names match those in the second column in the datagrid):
<StackPanel Margin="2">
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="All Business Processes" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Fixed Asset" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Order to Cash" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Purchase to Pay" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Stock and Make" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="General Accounting and Reporting" FontStyle="Italic" />
</StackPanel>
<TextBlock Text=" " />
</StackPanel>
So far I have not been able to make this work.
EDIT
Here is all my code so far:
MAINPAGE.XAML
<UserControl x:Class="TabControl.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="800">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<controls:TabControl Margin="3">
<controls:TabItem Header="Local / Monitoring Controls" />
<controls:TabItem Header="IBM Controls" />
<controls:TabItem Header="ITAC's" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Border BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" >
<StackPanel Orientation="Horizontal" >
<TextBlock Text="ITAC's - IT Automated Controls in Key Financial Systems" FontSize="12" FontWeight="Bold" Margin="5" />
<StackPanel Orientation="Horizontal" Margin="5">
<TextBlock Text="Date Last Updated: " />
<TextBlock Text="Test Date, needs binding" />
</StackPanel>
</StackPanel>
</Border>
<Border BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2">
<TextBlock Text="ERP controls from Sirius" FontStyle="Italic" Margin="5" />
</Border>
</StackPanel>
<Grid x:Name="Controls" Grid.Row="1" Background="#A1AEC3">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
<TextBlock Text="IT Automated Controls (Europe)" FontSize="12" FontWeight="Bold" Margin="5"/>
</Border>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="0,0,10,0" >
<TextBlock Text="Total Active Controls" FontWeight="Bold" Margin="5,5,5,0" TextAlignment="Right" />
<TextBlock Text="ITAC's Under Review" Margin="5,5,5,0" TextAlignment="Right" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Outstanding Issues from Previous Months" Margin="5,5,5,0" TextAlignment="Right" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="10,0,0,0" >
<TextBox Width="200" TextAlignment="Center" Text="33" />
<TextBox Width="200" TextAlignment="Center" Text="5" />
<TextBox Width="200" TextAlignment="Center" Text="0" />
</StackPanel>
</Grid>
<Grid x:Name="ITACs" Grid.Row="2" Background="#A1AEC3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Grid.Column="0" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
<StackPanel Orientation="Horizontal" Margin="3">
<StackPanel Orientation="Horizontal" >
<RadioButton GroupName="BusinessProcessTitle" />
<TextBlock Text="All ITAC's" FontWeight="Bold" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="100,0,0,0" >
<RadioButton GroupName="BusinessProcessTitle" />
<TextBlock Text="ITAC's Requiring Review" FontWeight="Bold" />
</StackPanel>
</StackPanel>
</Border>
<Border Grid.Row="1" Grid.RowSpan="2" Grid.Column="0" BorderThickness="1" BorderBrush="WhiteSmoke" CornerRadius="2" Margin="1" >
<StackPanel Margin="2">
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="All Business Processes" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1" />
<TextBlock Text="Fixed Asset" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Order to Cash" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Purchase to Pay" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="Stock and Make" FontStyle="Italic" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="1">
<RadioButton GroupName="BusinessProcessesGroup" />
<TextBlock Text="General Accounting and Reporting" FontStyle="Italic" />
</StackPanel>
<TextBlock Text=" " />
</StackPanel>
</Border>
<Border Grid.Row="0" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke" Background="#A1B9DD" CornerRadius="2" Margin="1" >
<Grid >
<TextBlock Text="ITAC Description" FontWeight="Bold" HorizontalAlignment="Left" Margin="3" />
<TextBlock Text="UL-AC1" FontStyle="Italic" HorizontalAlignment="Right" Margin="3"/>
</Grid>
</Border>
<Border CornerRadius="2" Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke">
<TextBlock TextWrapping="Wrap" Margin="3"
Text="Based on the asset class in the master data, the ERP system automatically calculates correct amounts for depreciation at the start of the depreciation run." />
</Border>
<Border CornerRadius="2" Grid.Row="2" Grid.Column="1" BorderThickness="1" BorderBrush="WhiteSmoke">
<StackPanel Orientation="Horizontal" Margin="1">
<TextBlock Text="Issue: " Margin="3,0,0,0" />
<TextBlock Text="Change Request to be created - Query Update Required" />
</StackPanel>
</Border>
</Grid>
<Grid x:Name="MainDataGrid" Grid.Row="5" >
<data:DataGrid x:Name="datagrid" AutoGenerateColumns="False" HorizontalAlignment="Stretch" IsReadOnly="True" VerticalAlignment="Top" ItemsSource="{Binding DataList}" Height="220" Margin="5">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="#" Binding="{Binding Number}" />
<data:DataGridTextColumn Header="Business Process" Width="300" Binding="{Binding BusinessProcess}" />
<data:DataGridTextColumn Header="Sub Process" Width="300" Binding="{Binding SubProcess}" />
<data:DataGridTextColumn Header="ITAC" Width="100" Binding="{Binding Itac}" />
<data:DataGridTextColumn Header="Status" Width="200" Binding="{Binding Status}" />
</data:DataGrid.Columns>
</data:DataGrid>
</Grid>
</Grid>
</controls:TabItem>
<controls:TabItem Header="User Access" />
<controls:TabItem Header="User Provisioning" />
<controls:TabItem Header="About" />
</controls:TabControl>
</Grid>
</UserControl>
MAINPAGE.XAML.CS
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.DataContext = new ItacViewModel();
}
}
DATA.CS
public class data
{
public int Number { get; set; }
public string BusinessProcess { get; set; }
public string SubProcess { get; set; }
public string Itac { get; set; }
public string Status { get; set; }
public data(int number, string businessProcess, string subProcess, string itac, string status)
{
Number = number;
BusinessProcess = businessProcess;
SubProcess = subProcess;
Itac = itac;
Status = status;
}
}
ITACVIEWMODEL.CS
public class ItacViewModel : ViewModelBase
{
public List DataList { get; set; }
public ItacViewModel()
{
var dataList = new List<data>
{
new data(1, "Fixed Asset", "Depreciation", "UL-AC1", "Under Review"),
new data(2, "Fixed Asset", "Depreciation", "UL-AC2", "Complete"),
new data(3, "Order to Cash", "Invoicing", "UL-AC3", "Under Review"),
new data(4, "Order to Cash", "Shipping Goods", "UL-AC4", "Under Review"),
new data(5, "Order to Cash", "Depreciation", "UL-AC5", "Complete"),
new data(6, "Order to Cash", "Depreciation", "UL-AC6", "Under Review"),
new data(7, "Order to Cash", "Depreciation", "UL-AC7", "Complete"),
new data(8, "Stock and Make", "Depreciation", "UL-AC8", "Under Review"),
new data(9, "Stock and Make", "Depreciation", "UL-AC9", "Under Review"),
new data(10, "General Accounting & Reporting", "Depreciation", "UL-AC10", "Complete")
};
DataList = dataList;
}
}
Instead of binding your DataGrid to List<data> you should bind data to ICollectionView. ICollectionView makes operations like grouping, filtering etc very simple to implement on some Data.
Take a look at this simple yet informative article on how to achieve filtering in WPF through ICollectionView
Edit
As Silverlight doesn't support provide an implementation of ICollectionView out of the box take a look at this or this article
Here's the trivial way: modify the Visibility of your Datagrid columns depending on the state of your radiobuttons.
XAML:
<data:DataGridTextColumn x:Name="colFixedAsset" Header="Status" Width="200" Binding="{Binding Status}" />
<RadioButton x:Name="radioFixedAsset" GroupName="BusinessProcessesGroup" IsChecked="False" Checked="radioFixedAsset_Checked" Unchecked="radioFixedAsset_Unchecked" />
Code behind:
private void radioFixedAsset_Checked(object sender, RoutedEventArgs e)
{
this.colFixedAsset.Visibility = System.Windows.Visibility.Visible;
}
private void radioFixedAsset_Unchecked(object sender, RoutedEventArgs e)
{
this.colFixedAsset.Visibility = System.Windows.Visibility.Collapsed;
}
If you're a MVVM purist, then add boolean properties to your view model and bind the IsChecked properties of your radiobuttons to those booleans. Also bind the Visibility property of your datagrid columns to those booleans using a converter.

Categories

Resources