Ejemplo n.º 1
0
        public void UpdateBindings(RLVItemDisplayVM userVal)
        {
            if (userVal.SelectedValueFromConverter != null && userVal.ConverterType != null)
            {
                if (userVal.ConverterType == 0) //Number
                {
                    userVal.Converter = new RLVNumericConverter((RLV.Core.Enums.RLVFormatters)userVal.SelectedValueFromConverter);
                }
                else //1=Time
                {
                    userVal.Converter = new RLVTimeConverter((RLV.Core.Enums.RLVFormatters)userVal.SelectedValueFromConverter);
                }
            }

            var controls = this.chartHeaderComponentsGrid.Children;

            foreach (var control in controls)
            {
                FrameworkElement con = control as FrameworkElement;

                // Exclude other controls
                if (con.Name.StartsWith("lbl") || string.IsNullOrEmpty(con.Name))
                {
                    continue;
                }

                if (con.Name == userVal.Name)
                {
                    var type         = control.GetType();
                    var typeName     = type.FullName;
                    var typeAssembly = type.Assembly;

                    Type controlType = Type.GetType($"{typeName}, {typeAssembly}");
                    if (controlType == typeof(TextBlock))
                    {
                        TextBlock textCtrl = control as TextBlock;

                        var visibilityBinding = new Binding {
                            Source = userVal, Path = new PropertyPath("Visibility"), Mode = BindingMode.TwoWay
                        };
                        BindingOperations.SetBinding(textCtrl, TextBlock.VisibilityProperty, visibilityBinding);

                        var valueBinding = new Binding {
                            Source = ViewModel, Path = new PropertyPath(textCtrl.Tag.ToString())
                        };
                        valueBinding.Converter = userVal.Converter;
                        BindingOperations.SetBinding(textCtrl, TextBlock.TextProperty, valueBinding);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateBindings(RLVItemDisplayVM userVal)
        {
            var controls = this.mainGrid.Children;

            foreach (var control in controls)
            {
                FrameworkElement con = control as FrameworkElement;

                // Exclude other controls
                if (con.Name.StartsWith("scaleSelection") || con.Name.StartsWith("btn") || con.Name.StartsWith("lbl") || string.IsNullOrEmpty(con.Name))
                {
                    continue;
                }

                if (con.Name == userVal.Name)
                {
                    var type         = control.GetType();
                    var typeName     = type.FullName;
                    var typeAssembly = type.Assembly;

                    Type controlType = Type.GetType($"{typeName}, {typeAssembly}");
                    if (controlType == typeof(DataGrid))
                    {
                        DataGrid gridCtrl = control as DataGrid;

                        var itemSourceBinding = new Binding {
                            Source = ViewModel, Path = new PropertyPath(gridCtrl.Tag.ToString())
                        };
                        var visibilityBinding = new Binding {
                            Source = userVal, Path = new PropertyPath("Visibility"), Mode = BindingMode.TwoWay
                        };

                        BindingOperations.SetBinding(gridCtrl, DataGrid.ItemsSourceProperty, itemSourceBinding);
                        BindingOperations.SetBinding(gridCtrl, DataGrid.VisibilityProperty, visibilityBinding);
                    }
                    else if (controlType == typeof(TextBox))
                    {
                        TextBox textCtrl = control as TextBox;

                        var valueBinding = new Binding {
                            Source = ViewModel, Path = new PropertyPath(textCtrl.Tag.ToString())
                        };
                        valueBinding.Converter = userVal.Converter;

                        var visibilityBinding = new Binding {
                            Source = userVal, Path = new PropertyPath("Visibility"), Mode = BindingMode.TwoWay
                        };

                        BindingOperations.SetBinding(textCtrl, TextBox.TextProperty, valueBinding);
                        BindingOperations.SetBinding(textCtrl, TextBox.VisibilityProperty, visibilityBinding);
                    }
                    else if (controlType == typeof(TextBlock))
                    {
                        TextBlock textCtrl = control as TextBlock;

                        var visibilityBinding = new Binding {
                            Source = userVal, Path = new PropertyPath("Visibility"), Mode = BindingMode.TwoWay
                        };
                        BindingOperations.SetBinding(textCtrl, TextBlock.VisibilityProperty, visibilityBinding);

                        bool foundHyperlink = false;
                        if (textCtrl.Inlines.Count > 0)
                        {
                            Hyperlink         link          = textCtrl.Inlines.First() as Hyperlink;
                            InlineUIContainer linkChild     = link.Inlines.First() as InlineUIContainer;
                            TextBlock         scoreLinkText = linkChild.Child as TextBlock;

                            Binding linkTextBinding = new Binding {
                                Source = ViewModel, Path = new PropertyPath(scoreLinkText.Tag.ToString())
                            };
                            linkTextBinding.Converter = userVal.Converter;

                            // Bind the text to be displayed
                            BindingOperations.SetBinding(scoreLinkText, TextBlock.TextProperty, linkTextBinding);

                            Binding linkUidBinding = new Binding {
                                Source = ViewModel, Path = new PropertyPath(scoreLinkText.ToolTip.ToString())
                            };

                            // Bind the session id to the UID property: This value will be used as a parameter in getting the score breakdown.
                            BindingOperations.SetBinding(scoreLinkText, TextBlock.UidProperty, linkUidBinding);

                            foundHyperlink = true;
                        }

                        if (foundHyperlink)
                        {
                            continue;
                        }

                        var valueBinding = new Binding {
                            Source = ViewModel, Path = new PropertyPath(textCtrl.Tag.ToString())
                        };
                        valueBinding.Converter = userVal.Converter;
                        BindingOperations.SetBinding(textCtrl, TextBlock.TextProperty, valueBinding);
                    }
                    else if (controlType == typeof(Label))
                    {
                        Label labelCtrl = control as Label;

                        var valueBinding = new Binding {
                            Source = ViewModel, Path = new PropertyPath(labelCtrl.Tag.ToString())
                        };
                        valueBinding.Converter = userVal.Converter;

                        var visibilityBinding = new Binding {
                            Source = userVal, Path = new PropertyPath("Visibility"), Mode = BindingMode.TwoWay
                        };

                        BindingOperations.SetBinding(labelCtrl, Label.ContentProperty, valueBinding);
                        BindingOperations.SetBinding(labelCtrl, Label.VisibilityProperty, visibilityBinding);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public void UpdateBindings(RLVItemDisplayVM userVal)
 {
     throw new NotImplementedException();
 }