The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
Unable to binding Button backgound in Style RRS feed

  • Question

  • In Disable state Unable to binding Background with "SignInDisableStateColor" with my view model code... After  binding button disapeared...

    Binding is not working in style code only

    In View:- 

    <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Background">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SignInDisableStateColor}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="BorderBrush">
                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonBorderBrushDisabled}"/>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>

    <Button Style="{StaticResource ButtonLoginStyle}" 
                            x:Uid="LoginView_SignIn"
                            Grid.Row="4"
                            Width="400" 
                            Height="45"
                            Background="{Binding CommonColor}"
                            Foreground="{Binding TextboxButtonColor}"
                            Margin="0,20,0,0"
                            FontSize="16"
                            IsEnabled="False"
                            Windows10version1809:CornerRadius="2">
    </Button>

    In ViewModel

            public SolidColorBrush SignInDisableStateColor
            {
                get
                {
                    return GetSolidColorBrush(resourceManager.GetString("#FFB9DEF8"));
                }
                set
                {

                }
            }


    Friday, April 12, 2019 11:15 AM

All replies

  • Hello Ankur tripathi,

    Your code is not complete so we actually do not know what you are doing. So you need to tell us what you wrote for GetSolidColorBrush and also how you set the binding from your code behind.

    Anyway, please notice the following:

    1. Make sure your code can look up the proper datacontext by directly set your datacontext. In this way when XAML is trying to look up the resource it can find out the rigth color.

    2. Make sure your calling of GetSolidColorBrush method returns the rigth color that the app needs. 

    Anyway, if I simply do the following, everything works as expect:

     public SolidColorBrush SignInDisableStateColor
            {
                          
                get
                {
                    return GetSolidColorBrush("#FFB9DEF8");
                }
                set
                {
    
                }
            }
    
            private SolidColorBrush GetSolidColorBrush(string v)
            {
                var color = (Color)XamlBindingHelper.ConvertValue(typeof(Color), v);
                SolidColorBrush brush = new SolidColorBrush(color);
                return brush;
            }

    Best regards,

    Barry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, April 15, 2019 1:08 AM