如何使用 WPF“行为”在 XAML 中?
我有一个应用程序,是我的前任编写的,它使用 WPF,但我真的不太熟悉它。
我必须获取他编译的 DLL,从此网页获取源代码并转换它到 VB,因为编译后的 DLL 过去可以在桌面安装上运行,但无法在我们的终端服务器上运行。
因此,我采用了 C# 代码,并将其转换
public static class BusyIndicatorBehavior
为
Public Module BusyIndicatorBehavior
我已删除了顶级命名空间(命名空间 ScrumSprintMonitor.UI.Wpf.Behaviors),因为我真的不知道它应该代表什么,现在,坦率地说,我已经不知道如何在我的 XAML 代码中引用它。
现有代码如下:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="{Binding Path=WindowTitle}"
UseLayoutRounding="True"
xmlns:l="clr-namespace:myAppName"
xmlns:b="clr-namespace:BusyIndicator;assembly=BusyIndicator" WindowState="Maximized">
<Window.Resources>
<ResourceDictionary Source="ResourceDictionary.xaml" />
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF8B8B8B" Offset="0"/>
<GradientStop Color="#FF484848" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grdFolder" b:BusyIndicatorBehavior.BusyState="{Binding Path=BusyState}">
如您所见,之前工作的DLL称为“BusyIndicator.DLL”,通过命名空间“b”引用,然后将b制成Grid的属性。不知何故。神奇的是。
有人可以猜测我如何引用我现在从现有项目中获得的“BusyIndicator”代码吗?我意识到我可能遗漏了很多重要信息,但我在这里一无所知。
I've got an application, written by my predecessor, which uses WPF, but I'm really not very familiar with it.
I've had to take a DLL he had compiled, fetch the source code from this webpage and convert it to VB, because the compiled DLL, which had worked on desktop installations in the past, refused to work on our terminal servers.
So, I have taken the C# code, and converted the
public static class BusyIndicatorBehavior
to
Public Module BusyIndicatorBehavior
I have removed the top-level namespace (namespace ScrumSprintMonitor.UI.Wpf.Behaviors) because I really don't know what it's supposed to represent and now, frankly, I have no idea how to reference this in the XAML code I have.
The existing code is as follows:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MainWindow"
x:Name="Window"
Title="{Binding Path=WindowTitle}"
UseLayoutRounding="True"
xmlns:l="clr-namespace:myAppName"
xmlns:b="clr-namespace:BusyIndicator;assembly=BusyIndicator" WindowState="Maximized">
<Window.Resources>
<ResourceDictionary Source="ResourceDictionary.xaml" />
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF8B8B8B" Offset="0"/>
<GradientStop Color="#FF484848" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grdFolder" b:BusyIndicatorBehavior.BusyState="{Binding Path=BusyState}">
As you can see, the previously-working DLL was called "BusyIndicator.DLL", is referenced with the namespace "b", and b is then made into a property of Grid. Somehow. Magically.
Can someone take a guess as to how I can reference the "BusyIndicator" code I've got now from the existing project? I realise I've probably left out a load of important information, but I'm running pretty clueless, here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,看了你的评论,我似乎更清楚了。
所需要做的就是将正确的命名空间添加到 xaml 中。
在
********
位置,您必须插入放置 BusyIndicator 类的命名空间。如果您使用 VB.NET 编写,请查看项目属性中的根命名空间。请注意,我删除了 xmlns 的汇编部分。如果 BusyIndicator 的命名空间是 myAppName,您可以删除 b 别名,并在 xaml 中将其替换为引用该命名空间的
l
。Ah, after your comment it seems more clear to me.
All that is needed is to add the correct namespace to the xaml.
At the spot of the
********
you have to insert the namespace in which the BusyIndicator class is placed. If you are writing in VB.NET, have a look at the root namespace in the properties of the project. Notice that I removed the assembly part of the xmlns.If the namespace of the BusyIndicator is myAppName you could remove the b alias and replace it in the xaml by
l
which refers to that namespace.