locked
Button in DataForm's EditTemplate cant get Disabled ! RRS feed

  • Question


  •  

     hello everyone ,

     i didnot posted here for a long time , and was thinking  that now i know silverlight fair enough . but today i found myself stuck in a problem so here it is .

     the dataform's edit template has 2 button's which i cant disable it , here is the code.

     

     
    
    <df:DataForm.EditTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <df:DataField>
                                        <TextBox  Text="{Binding Login_ID, Mode=twoway}" />
                                    </df:DataField>
                                    <df:DataField >
                                        <TextBox  Text="{Binding Login_Password, Mode=twoway}" />
                                    </df:DataField>
                                    <df:DataField >
                                        <TextBox  Text="{Binding DisplayName, Mode=twoway}" />
                                    </df:DataField>
                                    <StackPanel Orientation="Horizontal">
                                        <df:DataField>    
                                                <ListBox Width="150" Height="100" SelectionChanged="AllAgentRolesLstBox_SelectionChanged" SelectionMode="Single"  Name="AllAvailableAgentRoleNamesLstBox" ItemsSource="{Binding AllAvailableAgentRoleNames,Mode=TwoWay}" Loaded="AllAvailableAgentRoleNamesLstBox_Loaded"/>
                                        </df:DataField>
                                        <StackPanel VerticalAlignment="Center">
                                            <Button IsEnabled="{Binding SelectedItemFromAllRoles, ElementName=AgentPage, Converter={StaticResource nullToBooleanConvertor}}" Click="RoleMoveRightButton_Click" Content=">>" Name="RoleMoveRightButton" Loaded="RoleMoveRightButton_Loaded"/>
                                            <Button IsEnabled="{Binding SelectedAgentRole, ElementName=AgentPage, Converter={StaticResource nullToBooleanConvertor}}" Click="RoleMoveLeftButton_Click" Content="<<" Name="RoleMoveLeftButton" Loaded="RoleMoveLeftButton_Loaded"/>
                                         </StackPanel>
                                        <df:DataField>
                                            <ListBox SelectionChanged="CurrentAgentRoles_SelectionChanged" Width="150" Height="100"  SelectionMode="Single" Name="CurrentAgentRoles" DisplayMemberPath="RoleName" ItemsSource="{Binding AgentRoles, Mode=TwoWay}"/>
                                        </df:DataField>
                                    </StackPanel>
    
                                </StackPanel>
                            </DataTemplate>
                        </df:DataForm.EditTemplate>
      

     

    IT SEEM'S I CANNOT BIND TO  CODEBEHIND  USING BINDING FROM XAML , SO I THOUGHT TO DATABIND IN THE LOADED EVENTS OF THE BUTTON . BUT IT DIDN'T WORKED AS WELL , HERE IS HOW I BINDED IN MY CODEBEHIND.


    Button btn = (Button)sender;
    Binding binding = new Binding() { ElementName = "AgentPage", Converter = new NullToBooleanConvertor(), Path = new PropertyPath(SelectedItemFromAllSkillGroups) };
    btn.SetBinding(Button.IsEnabledProperty, binding);

     LATER I REPLACED THE PROPERTY IN MY PAGE (SelectedItemFromAllSkillGroups) WITH DEPENDECY PROPERTY , BUT STILL , IT DIDN'T WORKED .

    PLEASE IDENTIFY THE ISSUE.

    Wednesday, June 2, 2010 8:08 PM

Answers

  • Hi,

       No, you can not use Element Binding which it's target is out side the template.

       You can bind to a code behind property(as long as the data context is propagated correctly) , like what we usually do in MVVM.

       But in your scenerio, IMO, to add a property is worth to try.

    Best REgards

    Sunday, June 6, 2010 9:53 PM

All replies

  •  Can you verify if the binding value is ever set to false? That might be why its not working. Does the same binding work with just a plain button outside the dataform ?

    Thursday, June 3, 2010 9:48 AM
  •  very good question , i actually had forgotton this point .

     the binding value is never set to false.

     secondly what i found is , the convertor never got hit.

    regarding the question

      "Does the same binding work with just a plain button outside the dataform ?"

      well , i made a new  application and the binding did worked in it.here is the code which worked

     <Button IsEnabled="{Binding shouldButtonBeEnabled, ElementName=HomePage}" Content="hello" Width="100"/>

    Thursday, June 3, 2010 4:10 PM
  • Hi,

       Is the AgentPage element outside your EditTemplate?

       One thing to notice is that DataTemplate has it's own namescope, so basically it cant find the AgentPage for your.

    Best Regards

    Friday, June 4, 2010 12:33 AM
  •  yes , it is outside . AgentPage is the name of the navigation page and the property is in the code behind.

    if datatemplate has it's own namescope , does that mean , i cant bind anything inside datatemplate to a property in my codebehind file of the main page/control.

     

     

    Friday, June 4, 2010 8:03 AM
  • Hi,

       I am afraid, that's the strory now.

       Normally you can add a Property to your DataType to control the visibility.

       If you feel it will confuse the data and the layout boundary, IMO, you may take a look MVVM pattern

    Best Regards

    Saturday, June 5, 2010 11:44 PM
  •  hello there ,

    MVVM is a big architecture change . i cant effort to shift there at this point .

    so you are suggesting to add a property in my model class to control the UI visiblity ?

     thanks

    Jamal.

    P.S: are you also saying that i cannot access/bind to  any property in my codebehind when i am inside edit template ?

     

     

    Sunday, June 6, 2010 6:34 AM
  • Hi,

       No, you can not use Element Binding which it's target is out side the template.

       You can bind to a code behind property(as long as the data context is propagated correctly) , like what we usually do in MVVM.

       But in your scenerio, IMO, to add a property is worth to try.

    Best REgards

    Sunday, June 6, 2010 9:53 PM