小编Gre*_*egG的帖子

WPF 路径绑定到 PointCollection 不更新 UI

我正在尝试学习 MVVM 样式更新。不会那么游泳。

我坚持更新一个简单的矩形,该矩形基于对点集合的更改而绘制。在初始化时,UI 会更新,但在对 Point Collection 进行简单更改时,UI 中的 Path 不会更新。

我添加了一些 TextBlocks 以确保 Change 事件被触发,但此时我有点迷茫。

任何帮助表示赞赏:

XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ExampleGreg" x:Class="ExampleGreg.MainWindow"
        Title="MainWindow" Height="161.614" Width="324.087">
    <Grid x:Name="gridUser" MouseDown="click_MouseDown" >
        <Canvas x:Name="MeterCanvas" Margin="14,7,30,0" Background="#FFAFAFAF" Height="35" VerticalAlignment="Top">
            <Path Stroke="Black" StrokeThickness="2">
                <Path.Data>
                    <PathGeometry x:Name="geometry"/>
                </Path.Data>
            </Path>
            <Path Stroke="Black" StrokeThickness="2">
                <Path.Data>
                    <PathGeometry x:Name="polylinePwr">
                        <PathGeometry.Transform>
                            <ScaleTransform ScaleX="{Binding ActualWidth, ElementName=MeterCanvas}" ScaleY="{Binding ActualHeight, ElementName=MeterCanvas}" />
                        </PathGeometry.Transform>
                        <PathGeometry.Figures>
                            <PathFigure IsClosed ="True" StartPoint="{Binding Path=thePoints[0]}">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <PolyLineSegment Points="{Binding thePoints, UpdateSourceTrigger=PropertyChanged}" />
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml binding mvvm

6
推荐指数
1
解决办法
3453
查看次数

标签 统计

binding ×1

c# ×1

mvvm ×1

wpf ×1

xaml ×1