Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
690
Dynamic Image in Unbound Column of XamDataGrid
posted

Hi,

I have a unbound column in my xamdatagrid that will display button and image inside it.

Depending on the condition, the column can have image or no image (but it will always have button). The condition is known only when we start loading data in xamdatagrid.. i.e. we need to do some operation on one of the field to determine if the unbounded column will have image or not.

what is the best way to do this. For now i am doing like this:-

I am using CellValuePresenter to display button and image and I am trying to change image in RoutedCommand binded to Command property of Button.

 

<Style x:Key="myUnboundColumn" TargetType="{x:Type igDP:CellValuePresenter}">                    <Setter Property="Template">
     <Setter.Value>
                            <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                                <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                                    <Button Background="White"  BorderBrush="LightGray"                                                                                                x:Name="btn" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                              Command="{x:Static myns:mycls.EditCommand}"

                                            CommandParameter="{Binding}">
                                        <Grid>
                                         <Image HorizontalAlignment="Center" VerticalAlignment="Center"                                                                      Width="16" Height="16" Source="Image.png" x:Name="imgButton"/>
</Grid>  </Button></Grid></ControlTemplate></Setter.Value></Setter></Style>

 

and 

 <CommandBinding Command="{x:Static myns:mycls.EditCommand}"
CanExecute="Edit_CanExecute"      Executed="Edit_Executed"/>

So, I am trying to Access the image control inside my button control inside Edit_CanExecute method, so that i can check condition and remove the image where necessary. But i am unable to access it. what is the best way to change the source of that Image control dynamically.

thanks
miztaken