Click here to Skip to main content
15,902,874 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Silverlight and WCF issue Pin
Abhinav S23-Apr-10 0:21
Abhinav S23-Apr-10 0:21 
GeneralRe: Silverlight and WCF issue Pin
CrazyCoder2623-Apr-10 0:24
CrazyCoder2623-Apr-10 0:24 
GeneralRe: Silverlight and WCF issue Pin
Abhinav S23-Apr-10 1:00
Abhinav S23-Apr-10 1:00 
GeneralRe: Silverlight and WCF issue Pin
CrazyCoder2623-Apr-10 1:45
CrazyCoder2623-Apr-10 1:45 
GeneralRe: Silverlight and WCF issue Pin
CrazyCoder2625-Apr-10 20:48
CrazyCoder2625-Apr-10 20:48 
GeneralRe: Silverlight and WCF issu [modified] Pin
Abhinav S26-Apr-10 1:19
Abhinav S26-Apr-10 1:19 
GeneralRe: Silverlight and WCF issue Pin
CrazyCoder2623-Apr-10 17:43
CrazyCoder2623-Apr-10 17:43 
QuestionDatagridRow DetailsTemplate Problem Pin
vsaratkar22-Apr-10 10:43
vsaratkar22-Apr-10 10:43 
Hi,

I need to style dataGrid rows for different background colors for alternate rows, different backgroundColor for hover and on selection I want to show a details template and on selection I also want a dotted blue border on the DataRow.

To achieve this, I create two different dataGrid styles, one for Datagrid where no row is selected and one for datagrid where a row is selected.

To apply styles I am handling SelectionChanged event of Datagrid. I am posting my code to get better idea.

<code>
<Window x:Class="Locations"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WpfToolKit"
xmlns:Primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit"
xmlns:Linq="clr-namespace:Linq"
Style="{StaticResource ExtWindow}" Icon="/Icons/building.png" >
<Window.Resources>
<Style x:Key="DatagridRowStyleRowDetails" TargetType="dg:DataGridRow">
<Setter Property="Background" Value="#DFE8F6" />
<Setter Property="BorderBrush" Value="{StaticResource CheckeredBlues}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="DetailsVisibility" Value="Visible" />
<Setter Property="DetailsTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type Linq:Address}">
<StackPanel>
<Label Content="Address:" />
<StackPanel Margin="0,0,0,10">
<WrapPanel Margin="0,0,0,-10" >
<Label Content="{Binding Path=HouseNumber}" />
<Label Content="{Binding Path=Street}" />
<Label Content="{Binding Path=IdentifierType}" />
<Label Content="{Binding Path=IdentifierValue}" />
</WrapPanel>
<WrapPanel Margin="0,0,0,-10">
<Label Content="{Binding Path=City}"/>
<Label Content="{Binding Path=State}" />
<Label Name="lblZip" Style="{StaticResource fieldLabelStyle}" Content="{Binding Path=Zip}" />
</WrapPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DatagridRowStyleLocal" TargetType="dg:DataGridRow">
<Setter Property="Background" Value="#FFFFFF" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Width" Value="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type dg:DataGrid}},
Path=ActualWidth}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridRow}">
<Border Name="OuterBorder" SnapsToDevicePixels="True" BorderThickness="0, 1, 0, 0" BorderBrush="#FFFFFF" Background="{TemplateBinding Background}">
<Border Name="InnerBorder" SnapsToDevicePixels="True" BorderThickness="1, 0, 1, 1" BorderBrush="#EDEDED" Background="{TemplateBinding Background}">
<Primitives:DataGridCellsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" />
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="#FAFAFA" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="#EFEFEF" />
<Setter TargetName="OuterBorder" Property="BorderBrush" Value="#DDDDDD" />
<Setter TargetName="OuterBorder" Property="BorderThickness" Value="1" />
<Setter TargetName="InnerBorder" Property="BorderThickness" Value="0" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<DockPanel Width="500" >
<StackPanel>
<dg:DataGrid Style="{StaticResource DatagridStyle}" RowStyle="{StaticResource DatagridRowStyleLocal}" SelectionChanged="dataGridAddress_SelectionChanged" >
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Binding="{Binding Path=Location.LocationSerialNumber}" Header="Location" />
<dg:DataGridTextColumn Binding="{Binding Path=HouseNumber}" Header="No." />
<dg:DataGridTextColumn Binding="{Binding Path=Street}" Header="Street" />
<dg:DataGridTextColumn Binding="{Binding Path =City}" Header="City" />
<dg:DataGridTextColumn Binding="{Binding Path=State}" Header="State" />
<dg:DataGridTextColumn Binding="{Binding Path=Location.TotalObjects}" Header="Objects" />
<dg:DataGridTextColumn Binding="{Binding Path=Location.TotalServices}" Header="Services" />
<dg:DataGridTextColumn Width="60" Header="Time" />
<dg:DataGridTemplateColumn Header="Completed" IsReadOnly="True" >
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button IsEnabled="{Binding Path=IsCompleted}" Style="{StaticResource imageButtonStyle}" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
</StackPanel>
</DockPanel>
</Window>
</code>


in code behind Selechanged event:-
<code>
private void dataGridAddress_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
object selectedItem = e.AddedItems[0];
DataGridRow selectedRow = dataGridAddress.ItemContainerGenerator.ContainerFromItem(selectedItem) as DataGridRow;
selectedRow.Style = this.Resources["DatagridRowStyleRowDetails"] as Style;
foreach (var item in dataGridAddress.Items)
{
if (item != e.AddedItems[0])
{
var dataGridRow = dataGridAddress.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
dataGridRow.Style = this.Resources["DatagridRowStyleLocal"] as Style;
}
}

}
</code>

Styles are working ok as per requirement but if rows are selected rapidly then application crashes and throws exception
"The specified Visual is not an ancestor of this Visual."

Any idea how to fix this. I googled and found out that it is a bug, any one knows any workaround.
Thanks for reading,
Veena
Questionwindows application user control in wpf Pin
dashingsidds22-Apr-10 1:56
dashingsidds22-Apr-10 1:56 
AnswerRe: windows application user control in wpf Pin
dashingsidds22-Apr-10 19:33
dashingsidds22-Apr-10 19:33 
Questionneed 2 extract links from a html file Pin
shoeb0171721-Apr-10 21:19
shoeb0171721-Apr-10 21:19 
AnswerRe: need 2 extract links from a html file Pin
Pete O'Hanlon22-Apr-10 23:15
mvePete O'Hanlon22-Apr-10 23:15 
QuestionSilverlight and WCF issue Pin
CrazyCoder2621-Apr-10 17:36
CrazyCoder2621-Apr-10 17:36 
AnswerMessage Removed Pin
21-Apr-10 17:58
CrazyCoder2621-Apr-10 17:58 
GeneralRe: Silverlight and WCF issue Pin
Abhinav S21-Apr-10 18:54
Abhinav S21-Apr-10 18:54 
QuestionHow to combine multiple usercontrols into a single dll Pin
Prasoon Chaudhary21-Apr-10 2:28
Prasoon Chaudhary21-Apr-10 2:28 
QuestionSilverlight Database Access [modified] Pin
#realJSOP21-Apr-10 1:45
professional#realJSOP21-Apr-10 1:45 
AnswerRe: Silverlight Database Access Pin
daveyerwin21-Apr-10 15:09
daveyerwin21-Apr-10 15:09 
GeneralRe: Silverlight Database Access Pin
#realJSOP22-Apr-10 0:09
professional#realJSOP22-Apr-10 0:09 
AnswerRe: Silverlight Database Access Pin
Abhinav S21-Apr-10 18:50
Abhinav S21-Apr-10 18:50 
AnswerRe: Silverlight Database Access Pin
Michel Godfroid22-Apr-10 1:59
Michel Godfroid22-Apr-10 1:59 
AnswerRe: Silverlight Database Access Pin
econner1-May-10 17:47
econner1-May-10 17:47 
QuestionCommon Properties get disappeared after converting a WPF control into UserControl Pin
Prasoon Chaudhary21-Apr-10 0:15
Prasoon Chaudhary21-Apr-10 0:15 
AnswerRe: Common Properties get disappeared after converting a WPF control into UserControl Pin
BlitzPackage21-Apr-10 16:20
BlitzPackage21-Apr-10 16:20 
Questionwpf tooltip on datagrid cell. [modified] Pin
Ravi Mori19-Apr-10 23:38
Ravi Mori19-Apr-10 23:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.