C# 我是否正确使用此只读可绑定属性getter?

C# 我是否正确使用此只读可绑定属性getter?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我正在使用的一个NuGet软件包具有以下可用的bindable属性: VideoStateType VideoState { get; } // The current state of the VideoView: Empty, Error, Buffering, Playing, Paused, Stopped 下面的代码片段是否是“获取”VideoStateType的正确实现?我找到了关于只读属性的主题,但与VideoStateTypes无关。我在想一个控制台。WriteLine会帮我找

我正在使用的一个NuGet软件包具有以下可用的
bindable属性

VideoStateType VideoState { get; } // The current state of the VideoView: Empty, Error, Buffering, Playing, Paused, Stopped
下面的代码片段是否是“获取”VideoStateType的正确实现?我找到了关于只读属性的主题,但与VideoStateTypes无关。我在想一个
控制台。WriteLine
会帮我找到答案,但它不会出现在我的控制台中

是否正确实施

private VideoStateType videoState;

public VideoStateType VideoState
{
    get 
    {
        Console.WriteLine("The VideoState is ", videoState);
        return videoState; 
    }
}
下面是我的全部代码,如果你好奇的话。基本上,我有一个working
isBusy
属性,如果我愿意,它可以切换
false/true
。但是我只在
缓冲
视频状态期间尝试切换
isBusy=true

更新:5/20:
“私有void Videoplayer\u property更改”中将isBusy更改为isBusy

承载绑定的XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:PreAppStructure"
             xmlns:roxv="clr-namespace:Rox;assembly=Rox.Xamarin.Video.Portable"
             x:Class="PreAppStructure.Page3"
             Title="Welcome to page 3!">
    <Grid>
        <roxv:VideoView x:Name="VideoView" 
                        AutoPlay="True" 
                        LoopPlay="True"  
                        ShowController="True" 
                        Source="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" 
                        PropertyChangedCommand="{Binding PropertyChangedCommand}" />

        <StackLayout BackgroundColor="Black" 
                     HorizontalOptions="Center" 
                     VerticalOptions="Center" 
                     IsVisible="{Binding IsBusy}">

            <ActivityIndicator Color="White"
                x:Name="loader"
                IsRunning="{Binding IsBusy}" 
                VerticalOptions="Center" 
                HorizontalOptions="Center"
               />

            <Label x:Name ="loadingtext" 
                   Text="Loading...Please wait!" 
                   HorizontalOptions="Center" 
                   TextColor="White" 
                   IsVisible="{Binding IsBusy}"/>

        </StackLayout>
    </Grid>
</ContentPage>

如果您的XAML没有设置值,这意味着
BindingMode=OneWay
或者在本例中是
BindMode=OneTime
,那么您可以绑定到它

但是,您的
IsBusy
未正确启动,因为您正在设置备份字段,并且通知从未发送

VideoPlayer\u属性更改中
处理程序将
isBusy=false…或true更改为
isBusy=false…或true


我也不会称之为可绑定属性。。。它只是一个属性,您可以绑定到任何公共或内部属性(如果是同一程序集,则为内部属性)。从某种意义上说,使属性可绑定的方法是使用通知对其进行设置,就像使用
IsBusy
或使用
DependencyObject
使用
dependencProperty
或如果它是一个集合,则使用
INotifyCollectionChanged
ObservableCollection

谢谢你的评论,我还在学习C#的术语和内部工作原理,所以这非常有用。是的,我的XAML不包括
VideoState
绑定。我在我的帖子中的
RoxViewModel
类中有这一切。至于在
VideoPlayer\u属性已更改的处理程序中将
isBusy
替换为
isBusy
,它似乎不起作用。。。有趣的是,将
if
else
事件的属性
isBusy=true
设置为
if
else
实际上并不能使
isBusy
绑定为true(!)我的处理程序设置正确吗?@TomF您绑定到什么?你能给我看一下你正在使用绑定的代码吗?当然,我已经更新了我的原始帖子,加入了带有绑定的XAML。同样有趣的是,我在我的代码中使用了断点,我发现我的代码通过
get
,但从未进入
set
(除非它不需要,因为我没有启动什么?)。我也在更多地查看备份字段。@TomF我看不到在哪里连接了
Videoplayer\u PropertyChanged
。这个方法有什么影响吗?在那里放置一个断点。如果是这样的话,那么
的设置也应该会被点击。你的假设是正确的-
视频播放器的属性更改
没有连接。我假设我将其连接到类似于
OnPropertyChanged
,但使用
(对象发送者,System.ComponentModel.PropertyChangedEventArgs e)
?如果是这样的话,我不太确定如何填写这些标准,但我仍然在努力工作
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:PreAppStructure"
             xmlns:roxv="clr-namespace:Rox;assembly=Rox.Xamarin.Video.Portable"
             x:Class="PreAppStructure.Page3"
             Title="Welcome to page 3!">
    <Grid>
        <roxv:VideoView x:Name="VideoView" 
                        AutoPlay="True" 
                        LoopPlay="True"  
                        ShowController="True" 
                        Source="http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4" 
                        PropertyChangedCommand="{Binding PropertyChangedCommand}" />

        <StackLayout BackgroundColor="Black" 
                     HorizontalOptions="Center" 
                     VerticalOptions="Center" 
                     IsVisible="{Binding IsBusy}">

            <ActivityIndicator Color="White"
                x:Name="loader"
                IsRunning="{Binding IsBusy}" 
                VerticalOptions="Center" 
                HorizontalOptions="Center"
               />

            <Label x:Name ="loadingtext" 
                   Text="Loading...Please wait!" 
                   HorizontalOptions="Center" 
                   TextColor="White" 
                   IsVisible="{Binding IsBusy}"/>

        </StackLayout>
    </Grid>
</ContentPage>