框架可见的绑定无效

发布于 2025-02-09 14:22:40 字数 1183 浏览 1 评论 0原文

在最新的.NET MAUI Preview 17.3.0 Preview 2.0中,我对我对绑定的绑定有问题。可能与该版本无关。我没有使用mvvm ..在这里是我的代码:

 <Frame Background="LightBlue" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test" Margin="0,10,0,0" CornerRadius="25" HeightRequest="100">

在XAML的后端,我有一个布尔值我试图绑定到

private bool frameVisible;
        public bool FrameVisible
        {
            get
            {
                return frameVisible;
            }
            set
            {
                frameVisible = value;
                OnPropertyChanged("FrameVisible");
            }
        }

InotifiyPropertychang

public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            Console.WriteLine($"[App] Property changed {propertyName}");
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

我正在实现我的类构造函数中的 ,我正在设置BindingContext = this; 我想念什么?更改framevisible = false或true之后,OnProperTychanged触发器,但我看不到框架上的GUI更改。悬停在XAML上后的结果显示未找到用于绑定的数据。

I am having an issue with my Binding on isVisible in latest .Net Maui Preview 17.3.0 Preview 2.0. Probably unrelated to the version. I am not using MVVM..here is my code:

 <Frame Background="LightBlue" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test" Margin="0,10,0,0" CornerRadius="25" HeightRequest="100">

In the backend of the XAML, I have the boolean I am trying to bind to

private bool frameVisible;
        public bool FrameVisible
        {
            get
            {
                return frameVisible;
            }
            set
            {
                frameVisible = value;
                OnPropertyChanged("FrameVisible");
            }
        }

I am implementing INotifiyPropertyChanged

public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName)
        {
            Console.WriteLine(
quot;[App] Property changed {propertyName}");
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

In my class constructor I am setting bindingcontext = this;
What am I missing? The OnPropertyChanged triggers after changing frameVisible = false or true but I don't see any changes on GUI for the frame. The result after hovering over Xaml shows No datacontext found for binding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话里做英雄 2025-02-16 14:22:40

使用边框而不是框架。例子:

<Border Stroke="Black" StrokeThickness="2" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test">
    <Border.StrokeShape>
        <RoundRectangle CornerRadius="0,0,0,0" />
    </Border.StrokeShape>
    <!-- Object you wish to wrap border around -->
</Border>

Use Border instead of Frame. Example:

<Border Stroke="Black" StrokeThickness="2" IsVisible="{Binding FrameVisible}" x:Name="Frame_Test">
    <Border.StrokeShape>
        <RoundRectangle CornerRadius="0,0,0,0" />
    </Border.StrokeShape>
    <!-- Object you wish to wrap border around -->
</Border>
香橙ぽ 2025-02-16 14:22:40

当前被错误的不幸的是,似乎已经合并了一个修复程序。请参阅: https://github.com/dotnet/maui/maui/sissues/8044

IsVisible is currently bugged and not working unfortunately, seems like a fix has been merged. See: https://github.com/dotnet/maui/issues/8044

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文