
因此,我想在ListVIEw上面放置一个浮动图像(动画GIF?).
如何解决这个问题,一旦你有浮动图像或控制,你如何使GIF动画?
解决方法 这是我用来为 WPF创建类似AJAX的等待微调器的一些XAML.我使用几何和动画而不是动画GIF,你可以通过调整XAML来控制大小和速率:<!-- Style for AJAX-like wait spinners --><Style x:Key="WaitSpinnerStyle" targettype="Control"> <Setter Property="Foreground" Value="#888" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate targettype="Control"> <VIEwBox Visibility="{TemplateBinding Visibility}"> <Canvas RendertransformOrigin="0.5,0.5" WIDth="120" Height="120" > <Ellipse WIDth="21.835" Height="21.862" Canvas.left="20.1696" Canvas.top="9.76358" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="1.0"/> <Ellipse WIDth="20.835" Height="20.862" Canvas.left="2.86816" Canvas.top="29.9581" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.9"/> <Ellipse WIDth="19.835" Height="19.862" Canvas.left="0.00001" Canvas.top="57.9341" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.8"/> <Ellipse WIDth="17.835" Height="17.862" Canvas.left="12.1203" Canvas.top="83.3163" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.7"/> <Ellipse WIDth="16.835" Height="16.862" Canvas.left="36.5459" Canvas.top="98.1380" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.6"/> <Ellipse WIDth="14.835" Height="14.862" Canvas.left="64.6723" Canvas.top="96.8411" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.5"/> <Ellipse WIDth="13.835" Height="13.862" Canvas.left="87.6176" Canvas.top="81.2783" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.4"/> <Ellipse WIDth="12.835" Height="12.862" Canvas.left="98.165" Canvas.top="54.4140" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.3"/> <Ellipse WIDth="11.835" Height="11.862" Canvas.left="92.9838" Canvas.top="26.9938" Stretch="Fill" Fill="{TemplateBinding Foreground}" Opacity="0.2"/> <Canvas.Rendertransform> <Rotatetransform x:name="SpinnerRotate" Angle="0" /> </Canvas.Rendertransform> <Canvas.Triggers> <EventTrigger RoutedEvent="ContentControl.Loaded"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.Targetname="SpinnerRotate" Storyboard.TargetProperty="Angle" From="0" To="360" Duration="0:0:01.3" RepeatBehavior="Forever" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Canvas.Triggers> </Canvas> </VIEwBox> </ControlTemplate> </Setter.Value> </Setter></Style> 你这样使用它(如果你想改变颜色,请指定颜色):
<Control Style="{StaticResource WaitSpinnerStyle}" WIDth="35" /><Control Style="{StaticResource WaitSpinnerStyle}" WIDth="35" Foreground="Green" /> 上面的XAML看起来像这样(你必须想象它们在旋转!):
http://img23.imageshack.us/img23/1691/wpfwaitspinner.png
要在ListBox上方显示一个图层,请将其包装在GrID中,如下所示:
<GrID> <!-- LOADING overlay (for async-load) --> <border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsHitTestVisible="True" Background="#40000000" CornerRadius="4" Visibility="{Binding Path=IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <Control Style="{StaticResource WaitSpinnerStyle}" WIDth="35" Foreground="White" /> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="LOADING..." FontWeight="Bold" margin="0,5" Foreground="White" FontSize="12" /> </StackPanel> </border> <ListBox /></GrID> 使用网格意味着边框将出现在ListBox的顶部.在这种情况下,图层将显示为灰色,并将窃取任何鼠标 *** 作,从而有效地禁用基础ListBox.
请注意,此处与IsLoaded的绑定连接到我的视图模型.我在开始加载时将其设置为false,然后在加载完成时再次设置为true.请注意,我从调度程序线程(在工作线程上)加载我的项目,以便在我执行此工作时更新UI.
总结以上是内存溢出为你收集整理的c# – 在ListView上添加“加载”-image全部内容,希望文章能够帮你解决c# – 在ListView上添加“加载”-image所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)