Dev Express Grid control cell style not applied WPF - wpf

I tried to set the cell style for the grid control column within Lookupedit. but not applied at run time, but if I remove any property of the grid control column in debug mode at the time style applied, cell style should be applied when binding the data source, any idea to fix this, below is the code snippet
Thanks in advance,
Pandiyan Thangarasu
<UserControl x:Class="VisualizeWorkFlow.Legends"
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:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
xmlns:local="clr-namespace:VisualizeWorkFlow"
mc:Ignorable="d"
BorderBrush="LightGray">
<UserControl.Resources>
<local:LegendColorCodeConverterClass x:Key="LegendColorCodeConverter"/>
</UserControl.Resources>
<Grid Background="White">
<dxg:LookUpEdit DisplayMember="Name" dxc:ThemeManager.ThemeName="Office2010Silver" Name="PART_Editor" Width="300" >
<dxg:LookUpEdit.PopupContentTemplate>
<ControlTemplate>
<dxg:GridControl Name="PART_GridControl" CustomColumnDisplayText="PART_GridControl_CustomColumnDisplayText">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Name" Width="150" FieldName="Name" />
<dxg:GridColumn Header="Color Code" Width="30" FieldName="ColorCode">
<dxg:GridColumn.CellStyle>
<Style BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}" TargetType="dxg:CellContentPresenter">
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Background" Value="{Binding Value, Converter={StaticResource LegendColorCodeConverter}}"/>
</Style>
</dxg:GridColumn.CellStyle>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" ShowColumnHeaders="False" ShowIndicator="False" AutoExpandAllNodes="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
</ControlTemplate>
</dxg:LookUpEdit.PopupContentTemplate>
</dxg:LookUpEdit>
</Grid>
</UserControl>

Related

WPF XAML x:Type is underlined and states "MyColor" does not exist in the namespace .... Why?

I'm trying to display on a DataGrid a ObservableCollection. For each item in the ObservableCollection, I have a ComboBox that displays the currently selected item (MyColor in my example) and lets the user choose a different color from the combobox. This was working reasonably well when my Enum MyColor was in the same namespace as the MainWindow. However, to make the example closer to the problem I'm actually trying to solve I put the MyColor enum in a different project and namespace. I've included all code. In the XAML for the mainwindow, I have a ObjectDataProvider and the line
<x:Type TypeName="enu:MyColor" />
The word x:Type is underlined and has the message: The name MyColor does not exist in the namespace "clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
I've double and triple checked spelling, but don't see the problem. MyColor is defined in the namespace Library.EnumDefinitions. I'm wondering if the fact that the enum is in a separate namespace and project is causing me grief. The idea of using ObjectDataProvider can by found here for example:
https://brianlagunas.com/a-better-way-to-data-bind-enums-in-wpf/
The suggestion that there might be something special going on if your enum is in a different project/namespace is given here:
The name does not exist in the namespace in WPF application
I do have a reference to the different project in my Main project.
Any idea what is going on? If I can provide other information, please let me know.
Thanks,
Dave
MainWindow XAML
<Window x:Class="TrickyBindingProblems.MainWindow"
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:enu="clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ObjectDataProvider x:Key="EnumDataProvider" MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="enu:MyColor" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<DataGrid Grid.Column="1"
Margin="0"
HorizontalAlignment="Left"
AutoGenerateColumns="False"
Background="Transparent"
DataContext="{Binding}"
HeadersVisibility="Column"
ItemsSource="{Binding Cars}"
SelectedItem="{Binding SelectedItemProperty, Mode=TwoWay}"
RowBackground="Transparent"
RowHeight="30">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderBrush" Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTemplateColumn Width="*" Header="Make">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center"
Padding="5"
Text="{Binding Make}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" Header="Color (as ComboBox)">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource EnumDataProvider}}" SelectedItem="{Binding Color, Mode=TwoWay}">
<ComboBox.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Black" />
</Style>
</ComboBox.Resources>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
namespace Library.EnumDefinitions
{
public enum MyColor
{
Red,
Blue,
Green
}
}
UPDATE!!!
I believe I fixed my immediate problem. I changed the line:
xmlns:enu="clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
to:
xmlns:enu="clr-namespace:Library.EnumDefinitions"
Can someone tell me when you are suppose to use the "assembly" part and when you are not?

ComponentOne DataGridColumnHeaderPresenter Style Inheritance does not work (Silverlight)

I'm using ComponentOne C1DataGrid control for Silverlight. Standard StyleInheritance does not work.
Here is the code:
<UserControl x:Class="TestSLStyles.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:c1="http://schemas.componentone.com/winfx/2006/xaml"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:sys="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="BaseStyle" TargetType="Button">
<Setter Property="Background" Value="Yellow" />
</Style>
<Style x:Key="InheritedStyle" TargetType="Button" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Foreground" Value="Red" />
</Style>
<Style x:Key="dchpBase" x:Name="dchpBase" TargetType="c1:DataGridColumnHeaderPresenter">
<Setter Property="Background" Value="Yellow"/>
</Style>
<Style x:Key="dchpInherited" x:Name="dchpInherited" TargetType="c1:DataGridColumnHeaderPresenter" BasedOn="{StaticResource dchpBase}">
<Setter Property="Foreground" Value="Red"/>
</Style>
</UserControl.Resources>
<StackPanel>
<Button Content="HelloWorld" x:Name="btn1" />
<Button Content="HelloWorld" x:Name="btn2" Style="{StaticResource BaseStyle}" />
<Button Content="HelloWorld" x:Name="btn3" Style="{StaticResource InheritedStyle}" />
<c1:C1DataGrid x:Name="grd1">
<c1:C1DataGrid.Columns>
<c1:DataGridTextColumn Header="Column1" x:Name="cln1" />
<c1:DataGridTextColumn Header="Column2" x:Name="cln2" HeaderStyle="{StaticResource dchpBase}" />
<c1:DataGridTextColumn Header="Column3" x:Name="cln3" HeaderStyle="{StaticResource dchpInherited}" />
</c1:C1DataGrid.Columns>
</c1:C1DataGrid>
</StackPanel>
</UserControl>
As you can see on screen below, this code works fine for Button's style inheritance, but not for grid's column header:
The last column supposed to be with Yellow background and Red foreground, but base style is not inherited. Tested on Silverlight 5 and ComponentOne version 4.0.20103.86
Question was posted to ComponentOne's forum as well
The issue was fixed with the C1Silverlight Build : 5.0.20133.381
The latest build can be downloaded from the following link :http://prerelease.componentone.com/hotfixes/silverlight/C1Silverlight_5.0.20141.399_RC1.msi

How to reduce margins on buttons inside WrapPanel in WP7?

I'm trying to make a 'palette' in WP7. Visually, I'm after a look similar to the keyboard (SIP) or the dialler. I'm trying to make the margins around the buttons smaller than what they are now.
I'm having a lot of trouble with doing this, however - I've tried setting different margin thicknesses both directly and by attaching a style, but can't seem to get the problem sorted.
Here's an image of what I've got at the moment (sorry I'm a new user so it's just a link):
http://i40.tinypic.com/bj8g9f.jpg
And here's the relevant XAML I'm using.
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tk="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
x:Class="Mathflow.MainPage"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<Style x:Key="PaletteObjectStyle" TargetType="Button">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#1F1F1F"/>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0" />
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style x:Key="PaletteObjectText" TargetType="TextBlock">
<Setter Property="Margin" Value="8" />
</Style>
</phone:PhoneApplicationPage.Resources>
<StackPanel x:Name="LayoutRoot" DataContext="">
<Canvas x:Name="FlowContainer" Height="500">
</Canvas>
<ItemsControl x:Name="Palette" DataContext="{Binding Source={StaticResource FunctionsSource}}" ItemsSource="{Binding FunctionCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<tk:WrapPanel Orientation="Vertical" Height="200" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Style="{Binding Source={StaticResource PaletteObjectStyle}}">
<TextBlock Text="{Binding Display}" Style="{Binding Source={StaticResource PaletteObjectText}}"/>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</phone:PhoneApplicationPage>
Thanks very much! Any help would be greatly appreciated.
It appears that the WrapPanel applies a margin to the items it contains. There may be a way to retemplate it to override this, or (more simply) you could just set a negative margin on PaletteObjectStyle.
<Setter Property="Margin" Value="-6" />
You can also simplify your style bindings like this:
<Button Style="{StaticResource PaletteObjectStyle}">
<TextBlock Text="{Binding Display}" Style="{StaticResource PaletteObjectText}"/>
You can try setting Padding to 0. If that does not get you closer to what you need - just replace the entire Template of the button with your own ControlTemplate. You can extract the default template from the button using Blend. Just right click your button and select the option to edit template copy.
Personally I would not use a Button in this case if you are concerned about the Margins.
Instead use a Rectangle and Use the Gesture Lister to watch for the tap event (instead of a click) Only downside of this method is that you cannot use commanding from XAML but you could just launch the command in code if you require it.
See below: (Extract from http://bit.ly/lIleTe)
<Rectangle Fill="Orange" x:Name="rect">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="GestureListener_Tap" Hold="GestureListener_Hold" />
</toolkit:GestureService.GestureListener>

Accessing ListBox DisplayMemberPath data value in SelectedItem template

I am attempting to create a generic ListBox control to customize edit in place as well as other features.
In the example below, I want to bind the "Text" property of the ListBox "selected item" to the data value of the DisplayMemberPath in the viewed structure. Such XAML binding expression would replace the question marks in the code (Text="{Binding ????????????????").
Using a ContentPresenter instead of binding the text works for display purposes, but I have not been able to bind to the Text component used on the presenter. An alternative to finding the binding expression is to be able to get the Text content from the ContentPresenter.
I can think of a number of ways to accomplish this through code behind, but I am looking for a XAML solution if such thing exists.
I appreciate any ideas. I am almost sure there is a trivial answer to this, but after spending a couple days on it, I admit a nudge in the right direction would greatly help me.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="NobelLaureatesInPhysics"
XPath="/NobelLaureatesInPhysics">
<x:XData>
<NobelLaureatesInPhysics xmlns="">
<NobelLaureate>
<ID>1</ID>
<Name>Wilhelm Röntgen</Name>
<AwardDate>12/10/1901</AwardDate>
</NobelLaureate>
<NobelLaureate>
<ID>2</ID>
<Name>Hendrik Lorentz</Name>
<AwardDate>12/10/1902</AwardDate>
</NobelLaureate>
<NobelLaureate>
<ID>3</ID>
<Name>Pieter Zeeman</Name>
<AwardDate>12/10/1902</AwardDate>
</NobelLaureate>
</NobelLaureatesInPhysics>
</x:XData>
</XmlDataProvider>
<ControlTemplate x:Key="ItemTemplate"
TargetType="ListBoxItem">
<TextBlock Foreground="Black">
<ContentPresenter />
</TextBlock>
</ControlTemplate>
<ControlTemplate x:Key="SelectedItemTemplate"
TargetType="ListBoxItem">
<TextBox Background="Black"
Foreground="White"
Text="{Binding ????????????????"/>
</ControlTemplate>
<Style TargetType="{x:Type ListBoxItem}"
x:Key="ContainerStyle">
<Setter Property="Template"
Value="{StaticResource ItemTemplate}" />
<Style.Triggers>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Template"
Value="{StaticResource SelectedItemTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="TestListBoxStyle"
TargetType="{x:Type ListBox}">
<Setter Property="ItemContainerStyle"
Value="{DynamicResource ContainerStyle}" />
</Style>
</Window.Resources>
<Grid>
<ListBox Style="{DynamicResource TestListBoxStyle}"
ItemsSource="{Binding Source={StaticResource NobelLaureatesInPhysics}, XPath=NobelLaureate}"
DisplayMemberPath="Name"/>
</Grid>
{Binding Path=DisplayMemberPath, RelativeSource={RelativeSource Mode=FindAncestor, Type={x:Type ListBox}}
That should work

Constraining item heights in WPF ListBox, with indicator

I have a ListBox control in WPF which contains items of variable height (predominantly a large text block, so it's also affected by word wrapping). Since scrolling behaves badly when the height of an individual item gets too high (especially when close to the height of the ListBox itself), I want to constrain the max height of the individual items.
I've done that readily enough, by using a Style to set the MaxHeight of the ListBoxItem container.
My problem is that I would like to detect that an individual item has hit that constraint, and then style it differently.
This was my first attempt:
<Style x:Key="LogContainerStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="MaxHeight" Value="64" />
<EventSetter Event="MouseDoubleClick" Handler="LogEntry_MouseDoubleClick" />
</Style>
<DataTemplate x:Key="LogTemplate">
<Grid>
<TextBlock Text="{Binding Message}" />
<TextBlock x:Name="More" Text="(more)"
HorizontalAlignment="Right" VerticalAlignment="Bottom"
Foreground="DarkGray" Visibility="Collapsed" />
</Grid>
<DataTemplate.Triggers>
<Trigger ... height capped at MaxHeight? ...>
<Setter TargetName="More" Property="Visibility" Value="Visible" />
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
But I'm not sure how to write the trigger. Alternatives welcome.
Try the code below. I set the ListBoxItem.MaxHeight to 99. I then added a trigger in the DataTemplate that checks the ActualHeight of the root element in the template (i.e. "bd" below) and if it's 99, I change the BorderBrush. Hope this helps.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
ShowActivated="False"
Title="MainWindow" Height="350" Width="525">
<ListBox x:Name="lb">
<ListBox.ItemsSource>
<x:Array Type="{x:Type sys:Double}">
<sys:Double>250</sys:Double>
<sys:Double>100</sys:Double>
<sys:Double>50</sys:Double>
<sys:Double>25</sys:Double>
<sys:Double>99</sys:Double>
<sys:Double>120</sys:Double>
</x:Array>
</ListBox.ItemsSource>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="MaxHeight" Value="99"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border x:Name="bd" BorderBrush="Black" BorderThickness="1">
<TextBlock Text="{Binding}" Height="{Binding}" Background="LightGray"/>
</Border>
<DataTemplate.Triggers>
<Trigger SourceName="bd" Property="ActualHeight" Value="99">
<Setter TargetName="bd" Property="BorderBrush" Value="Red"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Window>

Resources