none
Static Resource Value from Binding Question

    Question

  • I have a UserControl that has a DataGrid on it.  It is bound to a Public Property in my ViewModel.

    One of the columns on the grid needs to be bound to a global boolean in the ViewModel.  That is to say, a ViewModel Property, not a property in the Object the Grid is Bound too.

    Doesn't look like you can do:

        <UserControl.Resources>
    <sys:Boolean x:Key="ManagedSignedFormsAuthorization">{Binding MyViewModelBoolean}</sys:Boolean>
    </UserControl.Resources>

    So I want to bind a column in my grid to a StaticResource and the StaticResource needs to get its value from the ViewModel.

    Friday, April 20, 2012 1:03 PM

Answers

  • Hi maikeu-sama,

    Please follow below code

    In ViewModel add a public property of bool type

    public bool  isFalse {get;set;}

    In MainPage.xaml

        <UserControl.Resources>
            <local:ViewModel x:Key="ViewModel" /> //here local namespace is refered to current project.
        </UserControl.Resources>

    <DataGrid>

    ...

                    <sdk:DataGridTemplateColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" >
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding isFalse, Source={StaticResource ViewModel}}" />
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>

    ...

    </DataGrid>

     

    Best Regards,

    Thursday, April 26, 2012 12:22 PM