This is a migrated thread and some comments may be shown as answers.

Binding Path for primitives:BackgroundGrid.LineStroke

4 Answers 111 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Svyatoslav
Top achievements
Rank 1
Svyatoslav asked on 31 Mar 2017, 09:03 AM

Good afternoon. How can I set the Binding Path for primitives:BackgroundGrid.LineStroke? Now I'm trying to do so

primitives:BackgroundGrid.LineStroke="{Binding Path=SelectedColorGrid, ElementName=GridColorEditor, Mode=TwoWay, Converter={StaticResource customColorToBrushConverter}}"

it's not working. For example, it works as

primitives:BackgroundGrid.CellSize="{Binding Path=CellSize , Mode=TwoWay}"   

My XAML code:

   <StackPanel Orientation="Horizontal" Margin="10 0">
                                                <CheckBox x:Name="ShowGridCheckBox" Content="{x:Static res:Resources.ShowGrid}" Width="110"
Margin="0 0 20 0" IsChecked="{Binding Path=GridEnable, Mode=TwoWay}"
Foreground="{telerik:Windows8Resource ResourceKey=StrongBrush}"
VerticalAlignment="Center" />
                                                <telerik:RadDropDownButton Width="80" DropDownWidth="210"
HorizontalContentAlignment="Right" FlowDirection="RightToLeft"
DropDownButtonPosition="Left">
                                                    <Border Width="12" Height="12" Margin="2 3"
Background="{Binding SelectedColorGrid ,Mode=TwoWay, ElementName=GridColorEditor, Converter={StaticResource customColorToBrushConverter}}"
BorderBrush="#d6d4d4" BorderThickness="1" />
                                                    <telerik:RadDropDownButton.DropDownContent>
                                                        <telerik:RadColorEditor x:Name="GridColorEditor" FlowDirection="LeftToRight"
ActiveSections="SaturationValuePad, HuePad" HistoryCapacity="8"
SelectedColor="{Binding SelectedColorGrid ,Mode=TwoWay, Converter={StaticResource customColorToBrushConverter}}" />
                                                    </telerik:RadDropDownButton.DropDownContent>
                                                </telerik:RadDropDownButton>
                                            </StackPanel>

 

<StackPanel Orientation="Horizontal" Margin="10 12 10 0">
                                                <TextBlock Text="{x:Static res:Resources.Cell}" Width="90" Margin="20 0" VerticalAlignment="Center" />
                                                <TextBox Width="80" Text="{Binding CellSize, Mode=TwoWay}" />
                                            </StackPanel>

 

where SelectedColorGrid and CellSize  its:

  public Size CellSize

        {
            get
            {
                Globals.Project.CellSize = cellSize;
                if (cellSize == new Size(0, 0))
                { cellSize = new Size(20, 20); }
                return this.cellSize;
            }
            set
            {
                if ((this.cellSize != value)&&(value!= new Size(0, 0)))
                {
                    this.cellSize = value;
                    this.OnPropertyChanged("CellSize");
                }
                else if ((cellSize == new Size(0, 0))|| (value == new Size(0, 0)))
                { cellSize = new Size(20, 20); }
            }
        }

        public Color SelectedColorGrid
        {
            get
            {
                Globals.Project.SelectedColorGrid = _selectedColorGrid;
                return this._selectedColorGrid;
            }
            set
            {
                if (this._selectedColorGrid != value)
                {
                    this._selectedColorGrid = value;
                    this.OnPropertyChanged("SelectedColorGrid");
                }
            }
        }

4 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 05 Apr 2017, 07:03 AM
Hi Svyatoslav,

The following Binding:
primitives:BackgroundGrid.LineStroke="{Binding Path=SelectedColorGrid, ElementName=GridColorEditor, Mode=TwoWay, Converter={StaticResource customColorToBrushConverter}}"

assumes the SelectedColorGrid is property of the RadColorEditor named 'GridColorEditor'. I can assure you RadColorEditor does not define such property. If the SelectedColor of the RadColorEditor is properly bound, then just bind the LineStroke to the SelectedColor. Is this an option ?

Such binding errors are always printed in the Output of the VisualStudio so we encourage you to check it regularly when using many bindings in XAML.


Regards,
Petar Mladenov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Svyatoslav
Top achievements
Rank 1
answered on 06 Apr 2017, 08:27 AM
I needed state SelectedColor in program and I need to know about the change SelectedColor to then save its value. Can you tell how can I do this?
0
Petar Mladenov
Telerik team
answered on 07 Apr 2017, 11:38 AM
Hi Svyatoslav,

Let's suppose you have *MainViewModel* class which introduces the SelectedColorGrid property:
public Color SelectedColorGrid
       {
           get
           {
               Globals.Project.SelectedColorGrid = _selectedColorGrid;
               return this._selectedColorGrid;
           }
           set
           {
               if (this._selectedColorGrid != value)
               {
                   this._selectedColorGrid = value;
                   this.OnPropertyChanged("SelectedColorGrid");
               }
           }
       }

If this class is DataContext for both Diagram and RadColorPicker then you can:

- bind the BackgroundGrid's LineStroke to SelectedColorGrid proeprty with converter, one way 
        - bind the SelectedColor of the ColorPicker to SelectedColorGrid property two way.

This way when you change the color with the RadColorPicker, then both property in the ViewModel and in Diagram will be updated. Is this an option ? If not, please add some more details from your requirement.

Regards,
Petar Mladenov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Svyatoslav
Top achievements
Rank 1
answered on 12 Apr 2017, 08:00 AM
Thank you very much, your advice helped, I solved the problem.
Tags
Diagram
Asked by
Svyatoslav
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Svyatoslav
Top achievements
Rank 1
Share this question
or