如何使用 WPF“行为”在 XAML 中?

发布于 2024-10-31 03:11:24 字数 1802 浏览 1 评论 0原文

我有一个应用程序,是我的前任编写的,它使用 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称为“BusyIndi​​cator.DLL”,通过命名空间“b”引用,然后将b制成Grid的属性。不知何故。神奇的是。

有人可以猜测我如何引用我现在从现有项目中获得的“BusyIndi​​cator”代码吗?我意识到我可能遗漏了很多重要信息,但我在这里一无所知。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜心 2024-11-07 03:11:24

啊,看了你的评论,我似乎更清楚了。

所需要做的就是将正确的命名空间添加到 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:********" WindowState="Maximized">

******** 位置,您必须插入放置 BusyIndi​​cator 类的命名空间。如果您使用 VB.NET 编写,请查看项目属性中的根命名空间。请注意,我删除了 xmlns 的汇编部分。

如果 BusyIndi​​cator 的命名空间是 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.

<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:********" WindowState="Maximized">

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文