首页 新闻 搜索 专区 学院

WPF绑定数据时界面不生效

0
悬赏园豆:50 [已关闭问题] 关闭于 2021-05-06 19:55

初学WPF,绑定数据时出现了一点小问题;
有这么一个数据类,引用了PropertyChanged.Fody,实现了INotifyPropertyChanged接口;

    public class DirectionArrowControlData : INotifyPropertyChanged
    {
        public DirectionArrowControlData()
        {
            Text = "";
            ForeColor = "#90EE90";
            ScaleX = 1;
            ScaleY = 1;
            Angle = 0;
        }
        public DirectionArrowControlData(DesignerItem designerItem) : this()
        {
            (designerItem.Content as DirectionArrowModule).DataContext = this;
        }
        
        /// <summary>
        /// 文本信息
        /// </summary>
        public string Text { get; set; }
        /// <summary>
        /// 字体颜色
        /// </summary>
        public string ForeColor { get; set; }
        /// <summary>
        /// 水平缩放比
        /// </summary>
        public double ScaleX { get; set; }
        /// <summary>
        /// 垂直缩放比
        /// </summary>
        public double ScaleY { get; set; }
        /// <summary>
        /// 旋转角度
        /// </summary>
        public int Angle { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }

这个数据类型绑定到一下界面时出现了问题:

<UserControl x:Class="GuideScreenSettingTool.Modules.DirectionArrowModule"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:settingviews="clr-namespace:GuideScreenSettingTool.SettingViews" 
             d:DataContext="{d:DesignInstance Type=settingviews:DirectionArrowControlData}"
             mc:Ignorable="d">
    <Viewbox IsHitTestVisible="False">
        <TextBlock Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                   Foreground="{Binding ForeColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                   FontFamily="../Fonts/#iconfont" RenderTransformOrigin="0.5,0.5">
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <RotateTransform Angle="{Binding Angle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <ScaleTransform ScaleX="{Binding ScaleX, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                    ScaleY="{Binding ScaleY, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </TransformGroup>
            </TextBlock.RenderTransform>
        </TextBlock>
    </Viewbox>
</UserControl>

当我尝试把数据实体绑定到该界面上时,修改数据并不会刷新界面信息,但是我绑定到另一个界面时又是可以正常刷新的,所以一时间不知道到底哪个地方出了问题,希望大佬们指点迷津啊。

一棵猪油草的主页 一棵猪油草 | 初学一级 | 园豆:114
提问于:2021-04-30 15:33
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册