Skip to content

Instantly share code, notes, and snippets.

@scichelli
Created March 27, 2012 14:49
Show Gist options
  • Save scichelli/2216553 to your computer and use it in GitHub Desktop.
Save scichelli/2216553 to your computer and use it in GitHub Desktop.
XAML binding to an object
A breakpoint in my Value Converter is never hit. Here's an excerpt of my Output window:
System.Windows.Data Warning: 68 : BindingExpression (hash=22895473): Found data context element: Image (hash=23663325) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=22895473): Activate with root item OperatingRoomCase (hash=12289189)
System.Windows.Data Error: 40 : BindingExpression path error: '' property not found on 'current item of collection' ''OperatingRoomCase' (HashCode=12289189)'. BindingExpression:Path=/; DataItem='OperatingRoomCase' (HashCode=12289189); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource')
System.Windows.Data Warning: 78 : BindingExpression (hash=22895473): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=22895473): TransferValue - using fallback/default value <null>
System.Windows.Data Warning: 87 : BindingExpression (hash=22895473): TransferValue - using final value <null>
<!-- For the grid (deleted irrelevant properties; temporarily have tracelevel set to high.) -->
<!-- I'm binding to "/" in an attempt to say "the current object, the whole thing." -->
<DataGrid x:Name="boardViewDataGrid" CanUserAddRows="False" AutoGenerateColumns="False" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="STATUS">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="AdvanceStatusButton_Click" Background="{x:Null}" BorderBrush="{x:Null}">
<Image Source="{Binding /, Converter={StaticResource statusImageConverter}, diagnostics:PresentationTraceSources.TraceLevel=High}" />
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!-- ... -->
</DataGrid.Columns>
</DataGrid>
public class OperatingRoomCaseToImagePathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var operatingRoomCase = value as OperatingRoomCase;
if (operatingRoomCase != null)
{
if (operatingRoomCase.IsCanceled && operatingRoomCase.CurrentStatus != OperatingRoomCaseStatus.Archived)
{
return "Images\\ex.png";
}
switch (operatingRoomCase.CurrentStatus)
{
case OperatingRoomCaseStatus.Scheduled:
return "Images\\opencircle.png";
case OperatingRoomCaseStatus.Ready:
return "Images\\minus.png";
case OperatingRoomCaseStatus.Started:
return "Images\\rightarrow.png";
case OperatingRoomCaseStatus.Completed:
return "Images\\check.png";
case OperatingRoomCaseStatus.Archived:
return "Images\\downarrowline.png";
default:
return string.Empty;
}
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<!-- At the top of that xaml file -->
<Page.Resources>
<UI:OperatingRoomCaseToImagePathConverter x:Key="statusImageConverter" />
<!-- ... -->
</Page.Resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment