Created
March 27, 2012 14:49
-
-
Save scichelli/2216553 to your computer and use it in GitHub Desktop.
XAML binding to an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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