C# 我是否正确使用此只读可绑定属性getter?
我正在使用的一个NuGet软件包具有以下可用的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会帮我找
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;
}
}
下面是我的全部代码,如果你好奇的话。基本上,我有一个workingisBusy
属性,如果我愿意,它可以切换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>