相关疑难解决方法(0)

强迫值的强制传播

tl; dr:强制值不会跨数据绑定传播.当代码隐藏不知道绑定的另一面时,如何强制更新数据绑定?


我正在使用一个CoerceValueCallbackWPF依赖属性,我坚持认为强制值不会传播到绑定的问题.

Window1.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace CoerceValueTest
{
    public class SomeControl : UserControl
    {
        public SomeControl()
        {
            StackPanel sp = new StackPanel();

            Button bUp = new Button();
            bUp.Content = "+";
            bUp.Click += delegate(object sender, RoutedEventArgs e) {
                Value += 2;
            };

            Button bDown = new Button();
            bDown.Content = "-";
            bDown.Click += delegate(object sender, RoutedEventArgs e) {
                Value -= 2;
            };

            TextBlock tbValue = new TextBlock();
            tbValue.SetBinding(TextBlock.TextProperty,
                               new Binding("Value") { …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf xaml dependency-properties coerce

9
推荐指数
1
解决办法
2363
查看次数

标签 统计

coerce ×1

data-binding ×1

dependency-properties ×1

wpf ×1

xaml ×1