SimpleMarkerSimple color binding

1990
3
02-08-2011 12:19 PM
MichaelRose
New Contributor III
I have incorporated a color picker that writes a color value to a global variable SolidColorBrush that I need to bind to a SimpleMarkerSymbol I am defining in my Grid.Resources code but I am having issues.

  <Grid.Resources>
            <esri:SimpleLineSymbol x:Key="DrawLineSymbol" Color="Green" Width="4" />
            <esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#3300FF00" BorderBrush="Green" BorderThickness="2" />
            <!--<esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="12" Style="Circle" />-->
            <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="{Binding silverlightRedliningTools.App.GlobalVariables.markerSymbolColor.Color, Mode=OneWay}" Size="12" Style="Circle" />
            <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Red" Width="4" />
            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />
        </Grid.Resources>


Nothing I have tried is writing the correct color to the Symbol.  Can anyone give me some direction to successfully bind to my grid resource?

Appreciate the assistance!
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I think this type of Binding statement relies on DataContext being set. You might need to set Binding Source instead.

I do not see where you define silverlightRedliningTools or markerSymbolColor. I think it would be something like
Color="{Binding Source={StaticResource markerSymbolColor}, Path=Color}" where markerSymbolColor is a key of another resource.
0 Kudos
MichaelRose
New Contributor III
Thank you for the quick response.  I am currently dealing with 3 XAML files (App, MainPage, and a Custom control).  I am initiating a global variable on the App.xaml, setting the global variable on the Custom Control xaml, and would like to use that global variable on the MainPage.xaml to change the color of my drawn graphics.

App.xaml.cs
        public static class GlobalVariables
        {
            public static SolidColorBrush markerSymbolColor;
            public static SolidColorBrush lineSymbolColor;
            public static SolidColorBrush fillSymbolColor;
        } 


ColorPickerControl.xaml.cs
        private void Color_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            this.SelectedColor = btn.Background as SolidColorBrush;

            silverlightRedliningTools.App.GlobalVariables.markerSymbolColor = this.SelectedColor;
            silverlightRedliningTools.App.GlobalVariables.lineSymbolColor = this.SelectedColor;
            silverlightRedliningTools.App.GlobalVariables.fillSymbolColor = this.SelectedColor;

            popUp.IsOpen = false;
        }


MainPage.xaml
        <Grid.Resources>
            <esri:SimpleLineSymbol x:Key="DrawLineSymbol" Color="Green" Width="4" />
            <esri:SimpleFillSymbol x:Key="DrawFillSymbol" Fill="#3300FF00" BorderBrush="Green" BorderThickness="2" />
            <!--<esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="12" Style="Circle" />-->
            <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="{Binding Source={StaticResource markerSymbolColor}, Path=Color}" Size="12" Style="Circle" />
            <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Red" Width="4" />
            <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#33FF0000" BorderBrush="Red" BorderThickness="2" />
        </Grid.Resources>


I have implemented the code that you supplied before and am getting the following error:

The resource "markerSymbolColor" could not be resolved.


I will continue to research and will update if anything changes on my end.

Thanks again for the help!
0 Kudos
JenniferNery
Esri Regular Contributor
You can do something like:

App.xaml:
             xmlns:media="clr-namespace:System.Windows.Media;assembly=System.Windows">
<Application.Resources>
 <media:SolidColorBrush x:Key="mySolidColorBrush" Color="Green"/>
</Application.Resources>


To change this value in your ColorPickerControl.xaml.cs
 SolidColorBrush brush = App.Current.Resources["mySolidColorBrush"] as SolidColorBrush;
 brush.Color = Colors.Yellow;


This will allow you to do:
<esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="{Binding Source={StaticResource mySolidColorBrush}}"  Size="12" Style="Circle" />
0 Kudos