private void UpdateContent() { if (panel == null) return; panel.Children.Clear(); if (Value == null) return; var enumValues = Enum.GetValues(Value.GetType()).FilterOnBrowsableAttribute(); var converter = new EnumToBooleanConverter { EnumType = Value.GetType() }; var relativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(RadioButtonList), 1); var descriptionConverter = new EnumDescriptionConverter(); foreach (var itemValue in enumValues ) { var rb = new RadioButton { Content = descriptionConverter.Convert(itemValue, typeof(string), null, CultureInfo.CurrentCulture) }; // rb.IsChecked = Value.Equals(itemValue); var isCheckedBinding = new Binding("Value") { Converter = converter, ConverterParameter = itemValue, Mode = BindingMode.TwoWay, RelativeSource = relativeSource }; rb.SetBinding(ToggleButton.IsCheckedProperty, isCheckedBinding); var itemMarginBinding = new Binding("ItemMargin") { RelativeSource = relativeSource }; rb.SetBinding(MarginProperty, itemMarginBinding); panel.Children.Add(rb); } }
public BindingExpression(DependencyObject target, DependencyProperty targetProperty, PropertyPath path, object source = null, RelativeSource relativeSource = null, string elementName = null, BindingMode mode = BindingMode.Default, UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default, IValueConverter converter = null, object converterParameter = null, object fallbackValue = null, object targetNullValue = null) { this.Target = target; this.TargetProperty = targetProperty; this.Path = path; this.Source = source; this.RelativeSource = relativeSource; this.ElementName = elementName; this.Mode = mode; this.UpdateSourceTrigger = updateSourceTrigger; this.Converter = converter; this.ConverterParameter = converterParameter; this.FallbackValue = fallbackValue; this.TargetNullValue = targetNullValue; Status = BindingStatus.Inactive; disableSourceUpdate = new ReentrancyLock(); disableTargetUpdate = new ReentrancyLock(); targetValue = new ObservableValue(Target.GetValue(TargetProperty)); targetValue.ValueChanged += OnTargetValueChanged; BindingMode resolvedBindingMode = Mode == BindingMode.Default ? GetDefaultBindingMode(Target, TargetProperty) : Mode; isSourceUpdateMode = resolvedBindingMode == BindingMode.TwoWay || resolvedBindingMode == BindingMode.OneWayToSource; isTargetUpdateMode = resolvedBindingMode == BindingMode.TwoWay || resolvedBindingMode == BindingMode.OneWay; sourceObserver = CreateSourceObserver(Target, Source, RelativeSource, ElementName); sourceExpression = new ObservableExpression(sourceObserver, Path ?? PropertyPath.Empty); // try to update the target (or the source on OneWayToSource) if (isTargetUpdateMode) { sourceExpression.ValueChanged += (sender, oldValue, newValue) => UpdateTargetOnSourceChanged(); UpdateTargetOnSourceChanged(); } else if (isSourceUpdateMode) { sourceExpression.ValueChanged += (sender, oldValue, newValue) => { if (Status == BindingStatus.UpdateSourceError && sourceExpression.Value != ObservableValue.UnsetValue && !disableTargetUpdate) { // source was connected UpdateSourceOnTargetChanged(); } }; UpdateSourceOnTargetChanged(); } if (UpdateSourceTrigger == UpdateSourceTrigger.LostFocus && isSourceUpdateMode && Target is UIElement) { ((UIElement)Target).LostFocus += OnLostFocus; } }
public static sw.FrameworkElementFactory ItemTemplate(bool editable, swd.RelativeSource relativeSource = null) { var factory = new sw.FrameworkElementFactory(typeof(swc.StackPanel)); factory.SetValue(swc.StackPanel.OrientationProperty, swc.Orientation.Horizontal); factory.AppendChild(ImageBlock()); factory.AppendChild(editable ? EditableBlock(relativeSource) : TextBlock()); return(factory); }
public static sw.FrameworkElementFactory EditableBlock(swd.RelativeSource relativeSource) { var factory = new sw.FrameworkElementFactory(typeof(EditableTextBlock)); var binding = new sw.Data.Binding { Path = new sw.PropertyPath("Text"), RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.LostFocus }; factory.SetBinding(EditableTextBlock.TextProperty, binding); return(factory); }
public AncestorBinding (string path) : base(path) { if (!IsPropertyReference(path)) throw new ArgumentException("Ancestor type not specified in path '{0}'.".Fmt(path), "path"); string propRef = path.Substring(1, path.IndexOf(')') - 1); string ownerTypeName = propRef.Substring(0, propRef.LastIndexOf('.')).Trim(); Type ownerType = GetTypeFromName(Path, ownerTypeName); if (ownerType == null) throw new ArgumentException("Ancestor type '{0}' not found using path '{1}'.".Fmt(ownerTypeName, path), "path"); RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, ownerType, 1); }
static GroupByControl() { // This DefaultStyleKey will only be used in design-time. DefaultStyleKeyProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new Markup.ThemeKey( typeof( Views.TableView ), typeof( GroupByControl ) ) ) ); FrameworkElementFactory staircaseFactory = new FrameworkElementFactory( typeof( StaircasePanel ) ); ItemsPanelTemplate itemsPanelTemplate = new ItemsPanelTemplate( staircaseFactory ); RelativeSource ancestorSource = new RelativeSource( RelativeSourceMode.FindAncestor, typeof( GroupByControl ), 1 ); Binding binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLineAlignmentProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineAlignmentProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLineOffsetProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineOffsetProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.ConnectionLinePenProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLinePenProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.StairHeightProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairHeightProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( GroupByControl.StairSpacingProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairSpacingProperty, binding ); itemsPanelTemplate.Seal(); ItemsControl.ItemsPanelProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( itemsPanelTemplate ) ); DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( GroupByControl.ParentGridControlChangedCallback ) ) ); DataGridControl.DataGridContextPropertyKey.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( new PropertyChangedCallback( GroupByControl.DataGridContextChangedCallback ) ) ); FocusableProperty.OverrideMetadata( typeof( GroupByControl ), new FrameworkPropertyMetadata( false ) ); }
void SetTemplate() { var source = new swd.RelativeSource(swd.RelativeSourceMode.FindAncestor, typeof(swc.TreeViewItem), 1); template1 = new sw.HierarchicalDataTemplate(typeof(ITreeItem)); template1.VisualTree = WpfListItemHelper.ItemTemplate(LabelEdit, source); template1.ItemsSource = new swd.Binding { Converter = new WpfTreeItemHelper.ChildrenConverter() }; Control.ItemTemplate = template1; template2 = new sw.HierarchicalDataTemplate(typeof(ITreeItem)); template2.VisualTree = WpfListItemHelper.ItemTemplate(LabelEdit, source); template2.ItemsSource = new swd.Binding { Converter = new WpfTreeItemHelper.ChildrenConverter() }; }
public MainWindow() { InitializeComponent(); System.Windows.Data.RelativeSource rs = new System.Windows.Data.RelativeSource(RelativeSourceMode.FindAncestor); rs.AncestorLevel = 1; rs.AncestorType = typeof(Grid); rs.AncestorType = typeof(DockPanel); //rs.Mode = RelativeSourceMode.Self; Binding binding = new Binding("Name") { RelativeSource = rs }; this.TextBox1.SetBinding(TextBox.TextProperty, binding); }
private static object GetRelativeSource(DependencyObject target, RelativeSource relativeSource, string elementName) { if (!elementName.IsNullOrEmpty()) { INameScope nameScope = NameScope.GetContainingNameScope(target); return(nameScope != null?nameScope.FindName(elementName) : null); } if (relativeSource == null || relativeSource.Mode == RelativeSourceMode.Self) { return(target); } if (relativeSource.Mode == RelativeSourceMode.TemplatedParent) { return(target is FrameworkElement ? ((FrameworkElement)target).TemplatedParent : null); } if (relativeSource.Mode == RelativeSourceMode.FindAncestor) { if (!(target is Visual)) { return(null); } Visual visual = (target as Visual).VisualParent; int level = relativeSource.AncestorLevel - 1; while (visual != null && (level > 0 || relativeSource.AncestorType != null && !relativeSource.AncestorType.IsInstanceOfType(visual))) { if (relativeSource.AncestorType == null || relativeSource.AncestorType.IsInstanceOfType(visual)) { level--; } visual = visual.VisualParent; } return(visual); } throw new Granular.Exception("RelativeSourceMode \"{0}\" is unexpected", relativeSource.Mode); }
static HierarchicalGroupByControlNode() { // Default binding to HierarchicalGroupByControlNode value FrameworkElementFactory staircaseFactory = new FrameworkElementFactory( typeof( StaircasePanel ) ); ItemsPanelTemplate itemsPanelTemplate = new ItemsPanelTemplate( staircaseFactory ); RelativeSource ancestorSource = new RelativeSource( RelativeSourceMode.FindAncestor, typeof( HierarchicalGroupByControl ), 1 ); Binding binding = new Binding(); binding.Path = new PropertyPath( HierarchicalGroupByControlNode.ConnectionLineAlignmentProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineAlignmentProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( HierarchicalGroupByControlNode.ConnectionLineOffsetProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLineOffsetProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( HierarchicalGroupByControlNode.ConnectionLinePenProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.ConnectionLinePenProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( HierarchicalGroupByControlNode.StairHeightProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairHeightProperty, binding ); binding = new Binding(); binding.Path = new PropertyPath( HierarchicalGroupByControlNode.StairSpacingProperty ); binding.Mode = BindingMode.OneWay; binding.RelativeSource = ancestorSource; staircaseFactory.SetBinding( StaircasePanel.StairSpacingProperty, binding ); itemsPanelTemplate.Seal(); ItemsControl.ItemsPanelProperty.OverrideMetadata( typeof( HierarchicalGroupByControlNode ), new FrameworkPropertyMetadata( itemsPanelTemplate ) ); DataGridControl.ParentDataGridControlPropertyKey.OverrideMetadata( typeof( HierarchicalGroupByControlNode ), new FrameworkPropertyMetadata( new PropertyChangedCallback( HierarchicalGroupByControlNode.ParentGridControlChangedCallback ) ) ); FocusableProperty.OverrideMetadata( typeof( HierarchicalGroupByControlNode ), new FrameworkPropertyMetadata( false ) ); }
public void ProcessPath(IServiceProvider serviceProvider) { if (string.IsNullOrWhiteSpace(_Path)) { _Binding = new Binding(); return; } var Parts = _Path.Split('.').Select(o => o.Trim()).ToArray(); RelativeSource oRelativeSource = null; string sElementName = null; var PartIndex = 0; if (Parts[0].StartsWith("#")) { sElementName = Parts[0].Substring(1); PartIndex++; } else if (Parts[0].ToLower() == "ancestors" || Parts[0].ToLower() == "ancestor") { if (Parts.Length < 2) throw new Exception("Invalid path, expected exactly 2 identifiers ancestors.#Type#.[Path] (e.g. Ancestors.DataGrid, Ancestors.DataGrid.SelectedItem, Ancestors.DataGrid.SelectedItem.Text)"); var sType = Parts[1]; var oType = (Type)new System.Windows.Markup.TypeExtension(sType).ProvideValue(serviceProvider); if (oType == null) throw new Exception("Could not find type: " + sType); oRelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, oType, 1); PartIndex += 2; } else if (Parts[0].ToLower() == "template" || Parts[0].ToLower() == "templateparent" || Parts[0].ToLower() == "templatedparent" || Parts[0].ToLower() == "templated") { oRelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent); PartIndex++; } else if (Parts[0].ToLower() == "thiswindow") { oRelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(Window), 1); PartIndex++; } else if (Parts[0].ToLower() == "this") { oRelativeSource = new RelativeSource(RelativeSourceMode.Self); PartIndex++; } var PartsForPathString = Parts.Skip(PartIndex); IValueConverter ValueConverter = null; if (PartsForPathString.Any()) { var sLastPartForPathString = PartsForPathString.Last(); if (sLastPartForPathString.EndsWith("()")) { PartsForPathString = PartsForPathString.Take(PartsForPathString.Count() - 1); _MethodName = sLastPartForPathString.Remove(sLastPartForPathString.Length - 2); ValueConverter = new CallMethodValueConverter(_MethodName); } } var Path = string.Join(".", PartsForPathString.ToArray()); if (string.IsNullOrWhiteSpace(Path)) { _Binding = new Binding(); } else { _Binding = new Binding(Path); } if (sElementName != null) { _Binding.ElementName = sElementName; } if (oRelativeSource != null) { _Binding.RelativeSource = oRelativeSource; } if (ValueConverter != null) { _Binding.Converter = ValueConverter; } }
public WpfEditableTextBindingBlock(Func <IIndirectBinding <string> > getBinding, swd.RelativeSource relativeSource) : base(typeof(EditableTextBlock)) { //var binding = new sw.Data.Binding { Path = TextPath, RelativeSource = relativeSource, Mode = swd.BindingMode.TwoWay, UpdateSourceTrigger = swd.UpdateSourceTrigger.PropertyChanged }; //SetBinding(EditableTextBlock.TextProperty, binding); }
private static PropertyPath GetDataContextRelativePath(PropertyPath path, object source, RelativeSource relativeSource, string elementName) { if (source != null || relativeSource != null || !elementName.IsNullOrEmpty()) { return path; } return path.Insert(0, new DependencyPropertyPathElement(FrameworkElement.DataContextProperty)); }
internal void SetValueTextDefaultStyle() { this.ValueText.Style = Defaults.DefaultValueTextStyle; // Set up the default margin binding Binding b = new Binding("Height"); b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; var relSource = new RelativeSource(); relSource.Mode = RelativeSourceMode.FindAncestor; relSource.AncestorType = typeof(Gauge); b.RelativeSource = relSource; b.Converter = new WpfGauge.Converters.ValueTextMarginConverter(); this.ValueText.SetBinding(TextBlock.MarginProperty, b); }
public BindingExpression(DependencyObject target, DependencyProperty targetProperty, PropertyPath path, object source = null, RelativeSource relativeSource = null, string elementName = null, BindingMode mode = BindingMode.Default, UpdateSourceTrigger updateSourceTrigger = UpdateSourceTrigger.Default, IValueConverter converter = null, object converterParameter = null, object fallbackValue = null, object targetNullValue = null) { this.Target = target; this.TargetProperty = targetProperty; this.Path = path; this.Source = source; this.RelativeSource = relativeSource; this.ElementName = elementName; this.Mode = mode; this.UpdateSourceTrigger = updateSourceTrigger; this.Converter = converter; this.ConverterParameter = converterParameter; this.FallbackValue = fallbackValue; this.TargetNullValue = targetNullValue; Status = BindingStatus.Inactive; disableSourceUpdate = new ReentrancyLock(); disableTargetUpdate = new ReentrancyLock(); targetValue = new ObservableValue(Target.GetValue(TargetProperty)); targetValue.ValueChanged += OnTargetValueChanged; BindingMode resolvedBindingMode = Mode == BindingMode.Default ? GetDefaultBindingMode(Target, TargetProperty) : Mode; isSourceUpdateMode = resolvedBindingMode == BindingMode.TwoWay || resolvedBindingMode == BindingMode.OneWayToSource; isTargetUpdateMode = resolvedBindingMode == BindingMode.TwoWay || resolvedBindingMode == BindingMode.OneWay; object resolvedSource = Source ?? GetRelativeSource(Target, RelativeSource, ElementName); sourceExpression = new ObservableExpression(resolvedSource, Path); // try to update the target (or the source on OneWayToSource) if (isTargetUpdateMode) { sourceExpression.ValueChanged += (sender, e) => UpdateTargetOnSourceChanged(); UpdateTargetOnSourceChanged(); } else if (isSourceUpdateMode) { sourceExpression.ValueChanged += (sender, e) => { if (Status == BindingStatus.UpdateSourceError && sourceExpression.Value != ObservableValue.UnsetValue && !disableTargetUpdate) { // source was connected UpdateSourceOnTargetChanged(); } }; UpdateSourceOnTargetChanged(); } if (((RelativeSource != null && RelativeSource.Mode != RelativeSourceMode.Self) || !ElementName.IsNullOrEmpty()) && Target is Visual) { ((Visual)Target).VisualAncestorChanged += OnTargetVisualAncestorChanged; } if (UpdateSourceTrigger == UpdateSourceTrigger.LostFocus && isSourceUpdateMode && Target is UIElement) { ((UIElement)Target).LostFocus += OnLostFocus; } }
private static object GetRelativeSource(DependencyObject target, RelativeSource relativeSource, string elementName) { if (!elementName.IsNullOrEmpty()) { INameScope nameScope = NameScope.GetContainingNameScope(target); return nameScope != null ? nameScope.FindName(elementName) : null; } if (relativeSource == null || relativeSource.Mode == RelativeSourceMode.Self) { return target; } if (relativeSource.Mode == RelativeSourceMode.TemplatedParent) { return target is FrameworkElement ? ((FrameworkElement)target).TemplatedParent : null; } if (relativeSource.Mode == RelativeSourceMode.FindAncestor) { if (!(target is Visual)) { return null; } Visual visual = (target as Visual).VisualParent; int level = relativeSource.AncestorLevel - 1; while (visual != null && (level > 0 || relativeSource.AncestorType != null && !relativeSource.AncestorType.IsInstanceOfType(visual))) { if (relativeSource.AncestorType == null || relativeSource.AncestorType.IsInstanceOfType(visual)) { level--; } visual = visual.VisualParent; } return visual; } throw new Granular.Exception("RelativeSourceMode \"{0}\" is unexpected", relativeSource.Mode); }
public static Binding BuildBinding(string path) { BindingDescriptor bindingDescriptor; if (BindingCache.TryGetValue(path, out bindingDescriptor)) return bindingDescriptor.ToBinding(); bindingDescriptor = new BindingDescriptor(); var match = _bindingPathRegex.Match(path); if (match.Groups["propertyPath"].Success) { bindingDescriptor.PropertyPath = match.Groups["propertyPath"].Value; } if (!match.Groups["dataContext"].Success && !match.Groups["markupSource"].Success && !match.Groups["xName"].Success) { throw new System.Windows.Markup.XamlParseException("Could not find source in: " + path); } if (match.Groups["xName"].Success) { bindingDescriptor.ElementName = match.Groups["xName"].Value; } if (match.Groups["markupSource"].Success) { string markupSourcePath = match.Groups["markupSource"].Value; Match selfExtensionMatch = _selfExtensionRegex.Match(markupSourcePath); if (selfExtensionMatch.Success) { bindingDescriptor.RelativeSource = RelativeSource.Self; } //DEM Added TemplatedParent and FindAncestor support else { Match parenttemplateExtensionMatch = _templateParentExtensionRegex.Match(markupSourcePath); if (parenttemplateExtensionMatch.Success) { bindingDescriptor.RelativeSource = RelativeSource.TemplatedParent; } else { Match RelativeAncestorExtensionMatch = _RelativeAncestorExtensionRegex.Match(markupSourcePath); if (RelativeAncestorExtensionMatch.Success) { // RelativeSource nr = new RelativeSource(RelativeSourceMode.FindAncestor); RelativeSource nr = new RelativeSource(); nr.AncestorType = TypeFromStringSolver.FromString(RelativeAncestorExtensionMatch.Groups["Type"].Value); if (RelativeAncestorExtensionMatch.Groups["Level"].Success) { nr.AncestorLevel = int.Parse(RelativeAncestorExtensionMatch.Groups["Level"].Value); } bindingDescriptor.RelativeSource = nr; } } } //End DEM } BindingCache.Add(path, bindingDescriptor); return bindingDescriptor.ToBinding(); }
/// <summary> /// Creates a new instance of <see cref="Column"/> class. /// </summary> public GridButtonCommand() { RelativeSource src = new RelativeSource(RelativeSourceMode.FindAncestor); src.AncestorType = typeof(DataGrid); this.RelativeSource = src; }
public AncestorBinding (string path, Type ancestor) : base(path) { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, ancestor, 1); }
private string SetFlyout(string header) { string regionName = string.Format("ViewRegionName_{0}", ++this.Count); this.CurrentFlyout = new Flyout(); Binding binding = null; RelativeSource rs; this.CurrentFlyout.AnimateOnPositionChange = true; this.CurrentFlyout.Theme = FlyoutTheme.Adapt; this.CurrentFlyout.Header = header; this.CurrentFlyout.IsOpen = false; rs = new RelativeSource(RelativeSourceMode.FindAncestor); rs.AncestorType = typeof(MetroWindow); binding = new Binding("ActualWidth"); binding.RelativeSource = rs; this.CurrentFlyout.SetBinding(Flyout.WidthProperty, binding); RegionManager.SetRegionManager(this.CurrentFlyout, this.regionManager); RegionManager.SetRegionName(this.CurrentFlyout, regionName); this.ContainerGrid.Items.Add(this.CurrentFlyout); this.CurrentFlyout.ApplyTemplate(); //this.CurrentFlyout.IsOpenChanged += flyout_IsOpenChanged; this.CurrentFlyout.IsHideComplete += CurrentFlyout_IsHideComplete; this.CurrentFlyout.Position = Position.Right; return regionName; }
private static IObservableValue CreateSourceObserver(DependencyObject target, object source, RelativeSource relativeSource, string elementName) { if (source != null) { return(new StaticObservableValue(source)); } if (relativeSource != null) { return(relativeSource.CreateSourceObserver(target)); } if (!elementName.IsNullOrEmpty()) { return(new ScopeElementSourceObserver(target, elementName)); } return(new DataContextSourceObserver(target)); }
public TemplateBinding() { RelativeSource = new RelativeSource { Mode = RelativeSourceMode.TemplatedParent }; }
public WpfImageTextBindingBlock(Func <IIndirectBinding <string> > textBinding, Func <IIndirectBinding <Image> > imageBinding, bool editable, swd.RelativeSource relativeSource = null) : base(typeof(swc.StackPanel)) { SetValue(swc.StackPanel.OrientationProperty, swc.Orientation.Horizontal); AppendChild(new WpfImageBindingBlock(imageBinding)); if (editable) { AppendChild(new WpfEditableTextBindingBlock(textBinding, relativeSource)); } else { AppendChild(new WpfTextBindingBlock(textBinding)); } }
private void LoadTabs() { View.RadTabControl.Items.Clear(); foreach (var promptGroup in PromptGroups) { Binding textBlockBinding = new Binding("IsSelected") {Mode = BindingMode.TwoWay}; RelativeSource rs = new RelativeSource {AncestorType = typeof (RadTabItem)}; textBlockBinding.RelativeSource = rs; textBlockBinding.Converter = new BackgroundColourConverter(); TextBlock textBlock = new TextBlock {Text = promptGroup.Name}; textBlock.SetBinding(TextBlock.ForegroundProperty, textBlockBinding); RadTabItem newTabItem = new RadTabItem { Header = textBlock, Tag = promptGroup }; View.RadTabControl.Items.Add(newTabItem); } View.RadTabControl.SelectedItem = View.RadTabControl.Items[0]; this.PromptGroup = ((RadTabItem) View.RadTabControl.SelectedItem).Tag as PromptGroup; View.RadTabControl.SelectionChanged += RadTabControlOnSelectionChanged; }
private FrameworkElementFactory CreateExpanderDock() { var dockFactory = new FrameworkElementFactory (typeof (DockPanel)); var source = new RelativeSource (RelativeSourceMode.FindAncestor, typeof (ExTreeViewItem), 1); Style expanderStyle = new Style (typeof (SWC.Primitives.ToggleButton)); expanderStyle.Setters.Add (new Setter (UIElement.FocusableProperty, false)); expanderStyle.Setters.Add (new Setter (FrameworkElement.WidthProperty, 19d)); expanderStyle.Setters.Add (new Setter (FrameworkElement.HeightProperty, 13d)); var expanderTemplate = new ControlTemplate (typeof (SWC.Primitives.ToggleButton)); var outerBorderFactory = new FrameworkElementFactory (typeof (Border)); outerBorderFactory.SetValue (FrameworkElement.WidthProperty, 19d); outerBorderFactory.SetValue (FrameworkElement.HeightProperty, 13d); outerBorderFactory.SetValue (Control.BackgroundProperty, Brushes.Transparent); outerBorderFactory.SetBinding (UIElement.VisibilityProperty, new Binding ("HasItems") { RelativeSource = source, Converter = BoolVisibilityConverter }); var innerBorderFactory = new FrameworkElementFactory (typeof (Border)); innerBorderFactory.SetValue (FrameworkElement.WidthProperty, 9d); innerBorderFactory.SetValue (FrameworkElement.HeightProperty, 9d); innerBorderFactory.SetValue (Control.BorderThicknessProperty, new Thickness (1)); innerBorderFactory.SetValue (Control.BorderBrushProperty, new SolidColorBrush (Color.FromRgb (120, 152, 181))); innerBorderFactory.SetValue (Border.CornerRadiusProperty, new CornerRadius (1)); innerBorderFactory.SetValue (UIElement.SnapsToDevicePixelsProperty, true); innerBorderFactory.SetValue (Control.BackgroundProperty, ExpanderBackgroundBrush); var pathFactory = new FrameworkElementFactory (typeof (Path)); pathFactory.SetValue (FrameworkElement.MarginProperty, new Thickness (1)); pathFactory.SetValue (Shape.FillProperty, Brushes.Black); pathFactory.SetBinding (Path.DataProperty, new Binding ("IsChecked") { RelativeSource = new RelativeSource (RelativeSourceMode.FindAncestor, typeof (SWC.Primitives.ToggleButton), 1), Converter = BooleanGeometryConverter }); innerBorderFactory.AppendChild (pathFactory); outerBorderFactory.AppendChild (innerBorderFactory); expanderTemplate.VisualTree = outerBorderFactory; expanderStyle.Setters.Add (new Setter (Control.TemplateProperty, expanderTemplate)); var toggleFactory = new FrameworkElementFactory (typeof (SWC.Primitives.ToggleButton)); toggleFactory.SetValue (FrameworkElement.StyleProperty, expanderStyle); toggleFactory.SetBinding (FrameworkElement.MarginProperty, new Binding ("Level") { RelativeSource = source, Converter = LevelConverter }); toggleFactory.SetBinding (SWC.Primitives.ToggleButton.IsCheckedProperty, new Binding ("IsExpanded") { RelativeSource = source }); toggleFactory.SetValue (SWC.Primitives.ButtonBase.ClickModeProperty, ClickMode.Press); dockFactory.AppendChild (toggleFactory); return dockFactory; }
private static PropertyPath GetDataContextRelativePath(PropertyPath path, object source, RelativeSource relativeSource, string elementName) { if (source != null || relativeSource != null || !elementName.IsNullOrEmpty()) { return(path); } return(path.Insert(0, new DependencyPropertyPathElement(FrameworkElement.DataContextProperty))); }
//----------------------------------------------------- // // Constructors // //------------------------------------------------------ /// <summary> Constructor. </summary> /// <param name="relativeSource">RelativeSource. </param> /// <exception cref="ArgumentNullException"> relativeSource is a null reference </exception> internal RelativeObjectRef(RelativeSource relativeSource) { if (relativeSource == null) throw new ArgumentNullException("relativeSource"); _relativeSource = relativeSource; }
public SelfBinding() { RelativeSource = new RelativeSource { Mode = RelativeSourceMode.Self }; }