Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

How to add a checkbox in this comboBox?

$
0
0

I would like to créate a multi select comboBox, but I don't have many knowledgement of axml, so I don't know wher to do it.

I use blend for VS 2013 and I créate a Project fo user control, add a new comboBox and I edit the template, the code is:

<UserControl
             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:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="GTS_WPF_Controles.ComboBoxCheckBox" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Width="Auto" Height="Auto"><UserControl.Resources><Style x:Key="ComboBoxFocusVisual"><Setter Property="Control.Template"><Setter.Value><ControlTemplate><Rectangle Margin="4,4,21,4" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/></ControlTemplate></Setter.Value></Setter></Style><LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0"><GradientStop Color="#F3F3F3" Offset="0"/><GradientStop Color="#EBEBEB" Offset="0.5"/><GradientStop Color="#DDDDDD" Offset="0.5"/><GradientStop Color="#CDCDCD" Offset="1"/></LinearGradientBrush><SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/><Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry><Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}"><Setter Property="OverridesDefaultStyle" Value="true"/><Setter Property="IsTabStop" Value="false"/><Setter Property="Focusable" Value="false"/><Setter Property="ClickMode" Value="Press"/><Setter Property="Background" Value="Transparent"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ToggleButton}"><Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true"><Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"><Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/></Grid></Themes:ButtonChrome><ControlTemplate.Triggers><Trigger Property="IsChecked" Value="true"><Setter Property="RenderPressed" TargetName="Chrome" Value="true"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0"><GradientStop Color="#ABADB3" Offset="0.05"/><GradientStop Color="#E2E3EA" Offset="0.07"/><GradientStop Color="#E3E9EF" Offset="1"/></LinearGradientBrush><Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}"><Setter Property="OverridesDefaultStyle" Value="true"/><Setter Property="AllowDrop" Value="true"/><Setter Property="MinWidth" Value="0"/><Setter Property="MinHeight" Value="0"/><Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/><Setter Property="Stylus.IsFlicksEnabled" Value="False"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TextBox}"><ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}"><Setter Property="OverridesDefaultStyle" Value="true"/><Setter Property="IsTabStop" Value="false"/><Setter Property="Focusable" Value="false"/><Setter Property="ClickMode" Value="Press"/><Setter Property="Background" Value="Transparent"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ToggleButton}"><Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RoundCorners="false" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"><Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/></Themes:ButtonChrome><ControlTemplate.Triggers><Trigger Property="IsChecked" Value="true"><Setter Property="RenderPressed" TargetName="Chrome" Value="true"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"><Grid x:Name="Placement" SnapsToDevicePixels="true"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions><Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom"><Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}"><Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"><ScrollViewer x:Name="DropDownScrollViewer"><Grid RenderOptions.ClearTypeHint="Enabled"><Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"><Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/></Canvas><ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/></Grid></ScrollViewer></Border></Themes:SystemDropShadowChrome></Popup><Themes:ListBoxChrome x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"/><TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/><ToggleButton Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/></Grid><ControlTemplate.Triggers><Trigger Property="IsKeyboardFocusWithin" Value="true"><Setter Property="Foreground" Value="Black"/></Trigger><Trigger Property="IsDropDownOpen" Value="true"><Setter Property="RenderFocused" TargetName="Border" Value="true"/></Trigger><Trigger Property="HasItems" Value="false"><Setter Property="Height" TargetName="DropDownBorder" Value="95"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/><Setter Property="Background" Value="#FFF4F4F4"/></Trigger><Trigger Property="IsGrouping" Value="true"><Setter Property="ScrollViewer.CanContentScroll" Value="false"/></Trigger><Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"><Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/><Setter Property="Color" TargetName="Shdw" Value="#71000000"/></Trigger><Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false"><Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/><Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/></Trigger></ControlTemplate.Triggers></ControlTemplate><Style x:Key="ComboBoxCheckBox" TargetType="{x:Type ComboBox}"><Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/><Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/><Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/><Setter Property="BorderThickness" Value="1"/><Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/><Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/><Setter Property="Padding" Value="4,3"/><Setter Property="ScrollViewer.CanContentScroll" Value="true"/><Setter Property="ScrollViewer.PanningMode" Value="Both"/><Setter Property="Stylus.IsFlicksEnabled" Value="False"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ComboBox}"><Grid x:Name="MainGrid" SnapsToDevicePixels="true"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/></Grid.ColumnDefinitions><Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom"><Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}"><Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"><ScrollViewer x:Name="DropDownScrollViewer"><Grid RenderOptions.ClearTypeHint="Enabled"><Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0"><Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/></Canvas><ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/></Grid></ScrollViewer></Border></Themes:SystemDropShadowChrome></Popup><ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxReadonlyToggleButton}"/><ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/></Grid><ControlTemplate.Triggers><Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"><Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/><Setter Property="Color" TargetName="Shdw" Value="#71000000"/></Trigger><Trigger Property="HasItems" Value="false"><Setter Property="Height" TargetName="DropDownBorder" Value="95"/></Trigger><Trigger Property="IsEnabled" Value="false"><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/><Setter Property="Background" Value="#FFF4F4F4"/></Trigger><Trigger Property="IsGrouping" Value="true"><Setter Property="ScrollViewer.CanContentScroll" Value="false"/></Trigger><Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false"><Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/><Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter><Style.Triggers><Trigger Property="IsEditable" Value="true"><Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/><Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/><Setter Property="IsTabStop" Value="false"/><Setter Property="Padding" Value="3"/><Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/></Trigger></Style.Triggers></Style></UserControl.Resources><Grid><ComboBox HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="105"
			ToolTip="Este es un control personalizado" Style="{DynamicResource ComboBoxCheckBox}"/></Grid></UserControl>

To add a checkbox to the comboBox I finde this code:

<UserControl x:Class="MultiSelectComboBox.MultiSelectComboBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><ComboBox
        x:Name="MultiSelectCombo"  
        SnapsToDevicePixels="True"
        OverridesDefaultStyle="True"
        ScrollViewer.HorizontalScrollBarVisibility="Auto"
        ScrollViewer.VerticalScrollBarVisibility="Auto"
        ScrollViewer.CanContentScroll="True"
        IsSynchronizedWithCurrentItem="True"><ComboBox.ItemTemplate><DataTemplate><CheckBox Content="{Binding Title}"
                          IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
                          Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
                           Click="CheckBox_Click"           /></DataTemplate></ComboBox.ItemTemplate><ComboBox.Template><ControlTemplate TargetType="ComboBox"><Grid ><ToggleButton 
                        x:Name="ToggleButton" 
                       Grid.Column="2" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                        Focusable="false"                           
                        ClickMode="Press" HorizontalContentAlignment="Left" ><ToggleButton.Template><ControlTemplate><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="18"/></Grid.ColumnDefinitions><Border
                  x:Name="Border" 
                  Grid.ColumnSpan="2"
                  CornerRadius="2"
                  Background="White"
                  BorderBrush="Black"
                  BorderThickness="1,1,1,1" /><Border 
                    x:Name="BorderComp" 
                  Grid.Column="0"
                  CornerRadius="2" 
                  Margin="1" 
                 Background="White"
                  BorderBrush="Black"
                  BorderThickness="0,0,0,0" ><TextBlock Text="{Binding Path=Text,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" 
                                               Background="White" Padding="3" /></Border><Path 
                  x:Name="Arrow"
                  Grid.Column="1"     
                  Fill="Black"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  Data="M 0 0 L 4 4 L 8 0 Z"/></Grid></ControlTemplate></ToggleButton.Template></ToggleButton><Popup 
                        Name="Popup"
                        Placement="Bottom"                        
                        AllowsTransparency="True" 
                        Focusable="False"  IsOpen="{TemplateBinding IsDropDownOpen}"
                        PopupAnimation="Slide"><Grid 
                                  Name="DropDown"
                                  SnapsToDevicePixels="True"  
                            MinWidth="{TemplateBinding ActualWidth}"
                                  MaxHeight="{TemplateBinding MaxDropDownHeight}"><Border 
                                    x:Name="DropDownBorder" 
                                   BorderThickness="1" Background="White"
                                    BorderBrush="Black"/><ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" DataContext="{Binding}"><StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" /></ScrollViewer></Grid></Popup></Grid><ControlTemplate.Triggers><Trigger Property="HasItems" Value="false"><Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/></Trigger><Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true"><Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/><Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/></Trigger></ControlTemplate.Triggers></ControlTemplate></ComboBox.Template></ComboBox></UserControl>

Biut this create the comboBox from zero, and I would like to modify the default comboBox style, and add only the checkBox. So as the code is different, I don't know how to translate to my particular case.

Thanks.


Growing DataGrids and Treeview inside Tab Control Tabitems

$
0
0

Hi,

 

I have a window that comes up on screen at a fixed size. When the window is expanded to full screen I want the controls to expand in a specified way.  I have two tab controls side by side in a grid.  One tab control contains a treeview. One tab control contains two data grids and four buttons. When the window is set to full screen I want the treeview to grow to full screen vertically while the width stays fixed and the grid containing the treeview stays aligned horizontally on the left side of the screen. The buttons will stay aligned horizontally on the right side of the window.  I want the datagrids to both grow to the right until they get within the set margin space of the buttons and for each datagrid to grow vertically for half the distance of the vertical container space available, so both datagrids will still be the same size vertically and horizontally. I have most of the behavior worked out. But, I can't get the two datagrids to grow vertically in the way I described. I have included the code for the XAML for this window. Eventually, there will be multiple tab items in both tab controls. I would love to solve this problem before adding more tab items. Any thouts on a solution? Thanks 

<Window x:Class="ControlResizing.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="611" Width="808"><Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"><TabControl  HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="206"><TabControl.ContextMenu><ContextMenu><MenuItem Header="Refresh"/></ContextMenu></TabControl.ContextMenu><TabItem><TabItem.Header><StackPanel Orientation="Horizontal"><TextBlock Text="Folder Tree" Margin="5,0,0,0" VerticalAlignment="Center"/></StackPanel></TabItem.Header><Grid VerticalAlignment="Stretch"><TreeView  Width="196" VerticalAlignment="Stretch" MinHeight="100" HorizontalAlignment="Left" Margin="0,0,0,10"/></Grid></TabItem></TabControl><Grid Margin="206,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"><TabControl  Margin="8,0"><TabItem  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"><TabItem.Header><StackPanel Orientation="Horizontal"><TextBlock Text="Books" Margin="5,0,0,0" VerticalAlignment="Center"/></StackPanel></TabItem.Header><Grid Background="#FFE5E5E5"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,-1"><Grid Background="#FFE5E5E5"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  ><DataGrid  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" MinHeight="255"  MinWidth="472" Margin="0,0,96,284" /></Grid><Grid Background="#FFE5E5E5"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,265,96,0" ><DataGrid  HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" MinHeight="277"  MinWidth="472" /></Grid><StackPanel HorizontalAlignment="Right" Height="100" Margin="477,43,0,0" VerticalAlignment="Top" Width="79"><Button Content="Button" Margin="0,0,0,20"/><Button Content="Button"/></StackPanel><StackPanel HorizontalAlignment="Right" Height="100" Margin="477,265,0,0" VerticalAlignment="Top" Width="79"><Button Content="Button" Margin="0,0,0,20"/><Button Content="Button"/></StackPanel></Grid></TabItem></TabControl></Grid></Grid></Window>

Copy datagrid row and paste it new row in WPF Data grid

$
0
0
I have a wpf datagrid which allows users to add rows. I need to add a functionality where in a user can copy a data row and on paste it is added as a new row. I am able to copy(Ctrl+C) a row, but on paste (Ctrl+V), all the items are pasted on to the first cell of the row. How can i paste it into each cell of the row.
<DataGrid Name="grdTest" HorizontalAlignment="Left" Grid.Row="0"  Margin="5,5,0,0" VerticalAlignment="Top" Height="426" Width="1034"
                  AlternationCount="2" ItemsSource="{Binding TestsList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
 <DataGrid.Columns>
<DataGridCheckBoxColumn Header="Is Active" Binding="{Binding Path=IsActive,Mode=TwoWay}">
  <DataGridTextColumn Width="90">
                                <DataGridTextColumn.Binding>
                                    <Binding Path="TestName" Mode="TwoWay">
                                        <Binding.ValidationRules>
                                           <localVal:ValidationRules/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </DataGridTextColumn.Binding>
                                <DataGridTextColumn.Header>
                                    <TextBlock Width="80" Text="Test Name" ToolTip=""/>
                                </DataGridTextColumn.Header>
                            </DataGridTextColumn>

<DataGridTextColumn.Binding>
                                    <Binding Path="TestType" Mode="TwoWay">
                                        <Binding.ValidationRules>
                                           <localVal:ValidationRules/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </DataGridTextColumn.Binding>
                                <DataGridTextColumn.Header>
                                    <TextBlock Width="80" Text="Test Type" ToolTip=""/>
                                </DataGridTextColumn.Header>
                            </DataGridTextColumn>
 </DataGrid.Columns>
 </DataGrid>

Filter a WPF data grid combo box based on selection of another combo box in the same datagrid

$
0
0
I have a wpf datagrid, which has two comboboxes. On selecting the first combobox the item source should change for the other combobox. The item source should be filtered based on the 1st combobox selection. Below is my code:
XAML:
<DataGrid Name="grdTest" HorizontalAlignment="Left" Grid.Row="0"  Margin="5,5,0,0" VerticalAlignment="Top" Height="426" Width="1034"
                  AlternationCount="2" ItemsSource="{Binding TestsList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
 <DataGrid.Columns>
<DataGridCheckBoxColumn Header="Is Active" Binding="{Binding Path=IsActive,Mode=TwoWay}">
  <DataGridTextColumn Width="90">
                                <DataGridTextColumn.Binding>
                                    <Binding Path="TestName" Mode="TwoWay">
                                        <Binding.ValidationRules>
                                           <localVal:ValidationRules/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </DataGridTextColumn.Binding>
                                <DataGridTextColumn.Header>
                                    <TextBlock Width="80" Text="Test Name" ToolTip=""/>
                                </DataGridTextColumn.Header>
                            </DataGridTextColumn>


    <DataGridTemplateColumn Width="120">
                                <DataGridTemplateColumn.Header >
                                    <TextBlock Text="Product Name" Width="109"/>
                                </DataGridTemplateColumn.Header>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox  Name="cbxProduct"
                                SelectedValue="{Binding ProductID,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                DisplayMemberPath="Product" SelectedValuePath="ProductID" SelectionChanged="cbxProduct_SelectionChanged_1"
                                ItemsSource ="{Binding Path=ProductsList}">
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>


<DataGridTemplateColumn Width="125">
                                <DataGridTemplateColumn.Header >
                                    <TextBlock Text="Program Name" Width="111"/>
                                </DataGridTemplateColumn.Header>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox  Name="cbxProgram"  SelectedValue="{Binding ProgramDimID,Mode=TwoWay}"
                                         DisplayMemberPath="Program" SelectedValuePath="ProgramID" SelectionChanged="cbxProgram_SelectionChanged"
                                         ItemsSource ="{Binding Path=ProgramsList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged }">                                          
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
 </DataGrid.Columns>
 </DataGrid>

private void grdTest_AddingNewItem(object sender, AddingNewItemEventArgs e)
        {
            e.NewItem = new tblTest { ProductsList = tempProducts,ProgramsList = tempPrograms };
        }

View Model:
 public ObservableCollection<tblTest> TestsList
        {
            get { return _objTests; }
            set
            {
                _objTests = value;
                NotifyPropertyChanged("TestsList");
            }
        }


 public partial class tblTestDim
    {   
        public bool IsActive{ get; set; }
        public string TestName { get; set; }
        public List<tblProduct> ProductList { get; set; }
        public List<tblProgramDim> ProgramsList { get; set; }
   }

public partial class tblProduct
   {   
        public int ProductID{ get; set; }
        public string Product{ get; set; }
   }

public partial class tblProgram
   {   
        public int ProgramID{ get; set; }
        public string Program{ get; set; }
   }

I tried setting the changing the second combobox itemsource, on cbxProduct_SelectionChanged_1 event as: (tblTest)(grdTest.CurrentCell.Item)).ProgramsList = FilteredList;

But it didnt work. Please let me know how I can achieve this.

WPF MVVM Messaging issue

$
0
0

Hello All,

My issue is that I have a WPF "window", incide the window I swap out WPF user controls, each having their own ViewModel.

So the initial View/ViewModel is MainView/VIewModel and I can pass messages to what ever usercontrol that is active.

In the main window I have s status bar that will show status of operations, like the number of tickets that have been returned for a stored procedure.

But when ViewModel B sends a message back to Main, to main, it does not register until I click on one of our menu buttons.  It is almost as if the message registeration requires the Window to be in focus.

How do I get around this.  I just want the status box to update when Main receives a message.

I would provide code, but the messaging is really generic.

Thanks


A valiant warrior dies but once, a coward dies a thousand times before his death.


Navigate to the previous frame

$
0
0

Hi,

I have an application that handel a group of frames from the main form.

Whether the second frame is shown, I would like to go back to the first frame using the C# code.

Is it possible?


Creating a standalone WPD app with multiple pages

$
0
0

Hi.

I am creating a WPF app for my college mini project. The app consist of a main windows with a background image and based on what button the user selects on the main window it has to display other pages while retaining the background image. I don't want it to have multiple windows or use the Navigationwindow as it is not exactly navigating between pages and I also want to be able to pass data between pages or by whatever means I would be able to accomplish this. This application is a demo app for using embedded SQL in my college project. I really have no idea how to go about this. Please help me. Thanks in advance. Any help would be appreciated.

Thanks.

TabControl with data templated listview and selecting controls via tag

$
0
0

I've got a TabControl with several tabs and datatemplated listviews inside of them.  In this scenario, I need to find a particular textbox by it's tag.  The textbox is in one of the tabs.  I know the tab to select from the data I have, which I do in my code.  That's not a problem.  Getting access to the textbox has been a problem for me.

I put together a small GitHub projecthere that shows the problem

Any help would be greatly appreciated.


Binding datatable to datagrid

$
0
0

Hello,

In my project, I use Infragistic's XamGrid. My database query result returns me a datatable which I need to bind with datagrid's ItemsSource.

MyGrid.ItemsSource = dataTable;

Binding datatable directly to DataGrid is not a problem but I want to convert my datatable to observablecollection. Converting to observable collection will help me in updating the subsequent changes (i.e. Adding/Editing/deleting of Rows from datatable) to UI layer faster. Now the problem is datarow object which is returned to me as part of datatable row collection is not always the same. What is returned as datarow depends on what I query and to which datatable. 

Because my datarow Item object type is not fixed I'm not able to use the ObservableCollection (because I need to specify the object type while creating the observable collection)

new ObservableCollection<T>(IEnumerable<T>)

I don't know <T> i.e. what is the datarow object type. In such case, is it possible to create the ObservableCollection and bind it to grid?

If using the ObservableCollection is not possible then what are the other ways to update the UI faster with database changes. (In my case per second around 100 rows may get changed/added/deleted).

Thanks,


Krunal C


Help

$
0
0
<Application.Resources><ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/></Application.Resources>

and;

xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
 How do I use this feature with the ;

WindowState, Maximize but not full screen

$
0
0

Hello all

 

I want to set the WindowState to Maximize but I do not want a full screen maximize.

I still want to see the WinowsBar bello, same as the maximize in WF application.

How can I achieve that?

Itzik

How to apply different styles corresponding to current system theme?

$
0
0

Hi,

In my WPF app I use several DataGrids. One DataGrid only uses DataGridTextColumns, and another one only uses DataGridTemplateColumns, with custom DataTemplates for each column. I noticed a difference in their appearance when using Classic theme: in DataGridTextColumns, the text of selected row(s) turns from black to white, a behavior not seen in DataGridTemplateColumns. Also in other themes, no text ever changes color.

Here is one sample DataGridTemplateColumn:

<DataGridTemplateColumn Header="Progress" Width="200"><DataGridTemplateColumn.CellTemplate><DataTemplate><Grid><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="Auto" /><ColumnDefinition Width="Auto" /></Grid.ColumnDefinitions><Label Grid.Row="0" Grid.Column="1" Content="{Binding PercentageString}" /><ProgressBar Grid.Row="0" Grid.Column="0"
                             Minimum="0" Maximum="100" Height="10" Width="100" Value="{Binding Percentage, Mode=OneWay}" /><Label Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="{Binding RemainingTimeString}" /></Grid></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>

Now I want the DataGridTemplateColumns to behave the same way as DataGridTextColumns: make the text of selected row(s) white, ONLY in Classic theme. How can I do that?

Actual code based on the snippet above will be much appreciated. Thank you.

Edit 1:

I tried this:

<Style x:Key="DataGridCellStyleOnClassicTheme" TargetType="{x:Type DataGridCell}" ><Style.Triggers><Trigger Property="IsSelected" Value="True"><Setter Property="Foreground" Value="White"/></Trigger></Style.Triggers></Style>

I set this style as CellStyle of DataGrid, but the text doesn't become white when selected. I added another setter that makes background green and it works, so I know this trigger does work.

Edit 2:

Switched from Labels to TextBlocks, and now the color does change. I'll go look up about when to use Labels and when to use TextBlocks.

The remaining question is how to apply the style only in Classic theme.

Edit 3:

I'm sorry I overlooked! I mixed up those DataGrids I used. DataGridTextColumns always turn their text white when selected, whatever the system is.

Just out of curiosity though, the question remains. How to apply different styles according to the current system theme? In as few lines of code as possible.

Combo boxes not updating in a datagrid

$
0
0

I have a WPF project with an entity framework model based on an SQL database and a dataset with the required tables. I have a main window with a frame which is loaded with various pages which works well. When I drag a table (set as a datagrid) from the dataset with all of the fields set as textfields and provide code (See below) to populate the datagrid from the table all works OK. However, if i delete the grid and change a field in the dataset to be a combobox and re-drag the datagrid as before. No matter what I try I cannot get the values for the field that now has a combobox to display the value from the database. The combobox is inside a  DataGridTemplateColumn  as follows:-

<DataGridTemplateColumn x:Name="stateColumn" Header="State" Width="80">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                           <ComboBox x:Name="cboState" 
                                      ItemsSource ="{StaticResource StateListString}"  
                                      SelectedValue="{Binding State, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      DisplayMemberPath="ValueString"
                                      SelectedValuePath ="ValueString" 
                              </ComboBox>
                         </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

private Athena_ArtEntities _context = new Athena_ArtEntities();

 private void Page_Loaded(object sender, RoutedEventArgs e)
        {   System.Windows.Data.CollectionViewSource moldingViewSource =
            ((System.Windows.Data.CollectionViewSource)(this.FindResource("moldingViewSource")));
            _context.Moldings.Load();
            moldingViewSource.Source = _context.Moldings.Local;

What am I missing? This is driving e crazy!!!!

How to combine DocumentPages into a document of a DocumentViewer wpf

$
0
0
I have a list of DocumentPage. Is it possible to iterate through the list and add each page to document of DocumentView.Document? I know I can do it with PageContent.

How to programmatically invoke DragSarted in code?

$
0
0

Hi,

public class ThumbCommandBehavior : Behavior<Thumb>
    {
        protected override void OnAttached()
        {
            if (this.AssociatedObject != null)
            {
                this.AssociatedObject.DragStarted += ThumbDragStarted;
                this.AssociatedObject.DragCompleted += ThumbDragCompleted;
            }
        }

        private void ThumbDragStarted(object sender, DragStartedEventArgs e)
        {
            TrackSkipStatus.IsSkipping = true;
        }

        private void ThumbDragCompleted(object sender, DragCompletedEventArgs e)
        {
            TrackSkipStatus.IsSkipping = false;
        }

        protected override void OnDetached()
        {
            if (this.AssociatedObject != null)
            {
                this.AssociatedObject.DragStarted -= ThumbDragStarted;
                this.AssociatedObject.DragCompleted -= ThumbDragCompleted;
            }
        }
    }

I would like to programmatically invoke the DragStarted in code.

As same as it were drag from original UI


Using DataTemplate & Styles with DataGrid

$
0
0

I have an application that requires many DataGrids displaying data from different sources in the same visual format. My data template displays an index in the row header along with a value both of which are stored in an ObservableCollection in my ViewModel. The data is bound correctly and shows on the screen as designed. However, the datagrids are not formatted correctly. I cannot figure out how to apply my DataGridCellStyle, DataGridStyle, and DataGridRowHeaderStyle to my datatemplate. Any help would be greatly appreciated. Thank you very much.

<UserControl x:Class="MyNamespace.Vpage2"
             xmlns:MyNamespace="clr-namespace:MyNamespace"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="700" d:DesignWidth="1200"><UserControl.Resources><Style x:Key="DataGridStyle" TargetType="{x:Type DataGrid}"><Setter Property="Height" Value="600"/><Setter Property="Width" Value="225"/><Setter Property="HorizontalAlignment" Value="Left"/><Setter Property="VerticalAlignment" Value="Top"/><Setter Property="AutoGenerateColumns" Value="False"/><Setter Property="BorderThickness" Value="1"/><Setter Property="VerticalScrollBarVisibility" Value="Disabled"/><Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/><Setter Property="CanUserAddRows" Value="False"/><Setter Property="CanUserDeleteRows" Value="False"/><Setter Property="CanUserResizeRows" Value="False"/><Setter Property="CanUserSortColumns" Value="False"/><Setter Property="HeadersVisibility" Value="Row"/><Setter Property="FontFamily" Value="Consolas"/><Setter Property="FontSize" Value="20"/><Setter Property="GridLinesVisibility" Value="None"/><Setter Property="SelectionUnit" Value="Cell"/><Setter Property="SelectionMode" Value="Single"/><Setter Property="RowHeaderWidth" Value="75"/></Style><Style x:Key="DataGridRowHeaderStyle" TargetType="{x:Type DataGridRowHeader}"><Setter Property="Background" Value="White"/></Style><Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}"><Style.Triggers><Trigger Property="IsSelected" Value="False"><Setter Property="BorderThickness" Value="0,0,0,0"/><Setter Property="Background" Value="White"/><Setter Property="Foreground" Value="Black"/></Trigger><Trigger Property="IsSelected" Value="True"><Setter Property="BorderThickness" Value="0,0,0,0"/></Trigger></Style.Triggers></Style><DataTemplate x:Key="MyTemplate"><DataGrid>    <DataGrid.Columns><DataGridTextColumn Binding="{Binding value}" Width="150" ><DataGridTextColumn.ElementStyle><Style TargetType="{x:Type TextBlock}"><Setter Property="HorizontalAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle></DataGridTextColumn></DataGrid.Columns><DataGrid.RowHeaderTemplate><DataTemplate><TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, 
                                      AncestorType={x:Type DataGridRow}}, 
                                      Path=Item.number}" /></DataTemplate></DataGrid.RowHeaderTemplate></DataGrid></DataTemplate></UserControl.Resources><Grid><GroupBox Header="View Sources" Margin="10,10,-10,-10"><Grid><DataGrid ItemsSource="{Binding source1}" Margin="50,10,909,68" ItemTemplate="{StaticResource MyTemplate}" /><DataGrid ItemTemplate="{StaticResource MyTemplate}" ItemsSource="{Binding source2}" Margin="339,10,624,68"/><DataGrid ItemTemplate="{StaticResource MyTemplate}" ItemsSource="{Binding source3}" Margin="624,10,339,68"/><DataGrid ItemTemplate="{StaticResource MyTemplate}" ItemsSource="{Binding source4}" Margin="909,10,54,68"/></Grid></GroupBox></Grid></UserControl>

public class Source
{
  int id;
  double value;
}

public class ViewModel
  {
    public ObservableCollection<Source> source1 { get; set; }
    public ObservableCollection<Source> source2 { get; set; }
    public ObservableCollection<Source> source3 { get; set; }
    public ObservableCollection<Source> source4 { get; set; }
}


Do Hidden objects effect a Window with it's SizeToConnect property set to WidthAndHeight?

$
0
0

I'm helping a friend with a WPF application. The Window's SizeToContent property is set to WidthAndHeight. In code some stack panels that contain objects, are hidden by setting the stack panel's Visibility property to Hidden when the application launches. Since setting a control's Visibility property to Hidden doesn't do anything, as far as the space on the window that's taken up by the stack panel, I'm thinking that is why the window appears larger than it should.

So just as a double check, is my reasoning correct? Wouldn't it be better to set the Visibility property to Collapsed?


Rod

User form TextBoxes binding to a List of property objects

$
0
0

Hi

I have a client form populated with Textboxes (Firstname, Lastname, etc) which I am binding to a Property class ClientInfo that implements INotifyPropertyChanged.  In addition, there is a 'Add Record' Button which when pressed will add the record poupulated by the user to a List property in ClientInfo object.  

I am instantiating the ClientInfo Property object in the xaml normally like this:

<local:ClientInfo x:Key="info"  />

and binding to the Textboxes like this:

<Label Style="{StaticResource label}" HorizontalAlignment="Right" VerticalAlignment="Center" Content="First Name" Name="firstNameLabel" Margin="0,0,15,0" Grid.Row="1" /><TextBox Text="{Binding Source={StaticResource ClientInfo}, Path=FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}"  />

I add the present record in  Add_Record_Button click event as :

 Private Sub addRecordButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles addRecordButton.Click
        If clientInfo.clientsList Is Nothing Then
            clientInfo.clientsList = New List(Of Jewellery.ClientInfo)
        End If
        clientInfo.clientsList.Add(CType(Me.FindResource("ClientInfo"), Jewellery.ClientInfo))
This adds properly and the form is cleared.  However when the next record is added, the first record is still there but overwritten with the second record's details in the List.  Any advice?  Thanks.


Export DataGrid to Excel with all visual style

$
0
0

Hi,

I have WPF DataGrid, so I need to export it to Excel and PDF. I found lots of topics about but all of them had to export to csv file or xls/xlsx without visual styles of the DataGrid.

For exemple: http://code.msdn.microsoft.com/WPF-Export-data-from-a-98a207a5

It's takes all DataGrid Rows but without Founts or Blod... In my case I have also a column that contains Images.

So,

How can I export DataGrid to Excel and PDF and save the same visual view style.

Thanks.



Fetching data from local database into WPF application

$
0
0

Hi.

I am designing an application for my school homework. It is a sample railways ticket booking WPF app. I created a local database called Trains and table called Table which contains the data of all the trains and routes. When the user types in the source and destination in two separated text boxes and clicks the button to fetch trains it has to search for trains that match the source and destination and display it in a suitable view. I am a complete beginner to c# and WPF so please help me to complete this assignment.

Thanks in advance.

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>