SetTimeOut问题(SetTimeOut problems)
我正在处理一个项目的问题。 我不是一个JS专家,所以如果这是一个愚蠢的问题,我很抱歉。
我有2个视频在彼此的顶部。 当我调用“开关”功能时,它会播放“静态”淡入淡出效果,然后切换两个视频的可见性。
一切正常,但是当我单击按钮以非常快速地调用该函数时,“静态”效果会变得粗糙并且一切都开始出错。
这是我正在使用的代码。 它会切换类名以隐藏视频。
function Switch(){ if(videoNieuw.className == "show"){ playNoise(1280, 720); btnswitch.className="controls now"; setTimeout(function(){ videoNieuw.className="hide"; videoOud.className = "show"; }, 500); }else if(videoOud.className = "show"){ playNoise(1280, 720); btnswitch.className="controls then"; setTimeout(function(){ videoOud.className = "hide"; videoNieuw.className="show"; }, 500); } }
setTimeout是这样的“静态”淡入淡出有时间淡化一点,让事情看起来更顺畅。
有没有其他方法,所以我可以把它放在没有故障的情况下?
I have a problem with a project i'm working on. I'm not in any way a JS expert so i'm sorry if this is a stupid thing to ask.
I have 2 video's that are on top of each other. when i call the function "switch" it plays a "static" fade effect and then switches the visability of both of the videos.
it all works fine, but when i click the button to call the function very fast, the "static" effect gliches out and everything starts to bug out.
here is the code that i am using. it switches the class name to hide the video.
function Switch(){ if(videoNieuw.className == "show"){ playNoise(1280, 720); btnswitch.className="controls now"; setTimeout(function(){ videoNieuw.className="hide"; videoOud.className = "show"; }, 500); }else if(videoOud.className = "show"){ playNoise(1280, 720); btnswitch.className="controls then"; setTimeout(function(){ videoOud.className = "hide"; videoNieuw.className="show"; }, 500); } }
The setTimeout is so the "static" fade has the time to fade a little bit and make things look smoother.
is there an alternative way so i can put this up without glitching?
原文:
最满意答案
好吧,如果你真的需要在
UserControl
公开SelectedItem
,为什么不用这样的属性扩展它呢?例如
public class MyUserControl : UserControl { private static readonly SomeType SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(SomeType), typeof(MyUserControl)); public SomeType SelectedItem { get { return (SomeType)GetValue(SelectedItemProperty); } set { SetValue(SelectedItemProperty, value); } } }
现在,您可以将
UserControl
DataGrid
的SelectedItem
绑定到其SelectedItem
属性。<MyUserControl> <DataGrid SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyUserControl}}" /> </MyUserControl>
现在,您只需要找到一种方法来访问
TabItem
的SelectedItem
属性。 但是我要把那部分留给你了。请注意,这只是我的想法的一个例子,它可能包含一些小错误。
Well if you really need to expose the
SelectedItem
from within aUserControl
why don't you extend it with such a property?E.g.
public class MyUserControl : UserControl { private static readonly SomeType SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(SomeType), typeof(MyUserControl)); public SomeType SelectedItem { get { return (SomeType)GetValue(SelectedItemProperty); } set { SetValue(SelectedItemProperty, value); } } }
So now you can bind the
SelectedItem
of theDataGrid
in theUserControl
to itsSelectedItem
property.<MyUserControl> <DataGrid SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MyUserControl}}" /> </MyUserControl>
Now you only have to find a way to access the
SelectedItem
property in theTabItem
. But I'm leaving that part to you.Please note, that this is only an illustration of my idea and it may contain some small errors.
相关问答
更多-
在WPF行中表示列表中的对象,而列是对象的属性。 这取决于DataGrid.ItemsSource是什么。如果您的ItemSource是BindedClass的数组,您可以通过以下方式获取选定的对象: BindedClass bc = (BindedClass)dataGridControl.SelectedItem; var prop1 = bc.Prop1; var prop2 = bc.Prop2; In WPF rows represent objects in a list and column ...
-
如果您想在数据网格中添加一个新行,为什么不简单地创建一个添加命令,在其中向ObservableCollection添加一个新项目并将此新项目设置为您的selectedItem,以便在您的数据网格中选择它。 private void AddCommandExecute() { var toAdd = new MyItem();//new "row item" this.MyCollection.Add(toAdd);//add to collection with au ...
-
你需要做一些事情: 将您的属性更新为类型object : public RelayCommand
-
一个可能的解决方案是使用Bindings 。 每行都绑定到不同的项目,因此每个项目可以将其各自的属性绑定到这些按钮。 您必须在对象的模型中提供额外的属性。 您可以将简单的booleans绑定到按钮的IsEnabled属性。 将默认值设置为false 。 这样,您可以编辑所选项目的属性,并自动更改相应按钮的属性。 A possible solution is the use of Bindings. Each row is bound to a different item, so each item can ...
-
如何使用扩展选择模式了解DataGrid中的选定项?(How to know the selected items in a DataGrid with extended selection mode?)[2022-10-31]
确保您的Datagrid属性> SelectionUnit是Row 。我希望这个能帮上忙。 Make sure your Datagrid Property > SelectionUnit is Row .I hope this will help. -
您可以使用SelectedItem属性访问DataGrid的当前选定项。 然后,您可以调用Remove方法从DataGrid删除该项 var selectedItem = myDataGrid.SelectedItem; if (selectedItem != null) { myDataGrid.Items.Remove(selectedItem); } 在第一行之后,您需要从项目中提取信息(例如,一些Id),以便在数据库中删除它。 通常将SelectedItem转换为用于绑定到网格的对象。 另见 ...
-
这对我来说没问题,我在一行按钮上使用它: Command="{Binding Path=DataContext.MyClickRowEventCommand, RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=DataC ...
-
DataGrid CellTemplate,将DataContext作为命令参数传递(DataGrid CellTemplate, Pass DataContext as Command Parameter)[2022-01-05]
您可以使用以下命令将DataTemplate中的当前DataContext(这是行中显示的元素)绑定到CommandParameter: CommandParameter="{Binding}" You can bind the current DataContext in your DataTemplate (wich is the element displayed in the row) to the CommandParameter by using: CommandParameter="{Bin ... -
与其尝试使用命令参数,不如创建一个属性来存储选定的行: private Model row; public Model Row { get { return row; } set { if (row != value) { row = value; base.RaisePropertyChanged("Row"); ...
-
好吧,如果你真的需要在UserControl公开SelectedItem ,为什么不用这样的属性扩展它呢? 例如 public class MyUserControl : UserControl { private static readonly SomeType SelectedItemProperty = DependencyProperty.Register("SelectedItem", typeof(SomeType), typeof(MyUserControl)); ...