【问题标题】:How to use a WPF "behavior" in XAML?如何在 XAML 中使用 WPF“行为”?
【发布时间】:2011-04-07 10:48:14
【问题描述】:

我有一个应用程序,由我的前任编写,使用 WPF,但我真的不是很熟悉。

我不得不取出他编译的 DLL,从this webpage 获取源代码并将其转换为 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”代码吗?我意识到我可能遗漏了大量重要信息,但在这里我很无知。

【问题讨论】:

  • “我如何引用我现在从现有项目中获得的“BusyIndi​​cator”代码”是什么意思?如果上面的代码有效,你已经有一个参考。
  • 对不起,我不清楚。上面的代码是现有代码,它引用了一个 DLL。此 DLL 在我们的终端服务器上不起作用。我已经获得了我认为是该 DLL 的源代码,并将其集成到我的代码中。我现在拥有的是一些工作(希望如此)的 VB 代码,但必须对其进行更改以考虑到 BusyIndi​​cator 现在是项目不可或缺的一部分而不是外部的变化的非工作 XAML。上面的代码是原代码,不起作用。

标签: .net wpf vb.net xaml


【解决方案1】:

啊,在你的评论之后,我似乎更清楚了。

只需将正确的命名空间添加到 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。

【讨论】:

  • 啊!我曾尝试这样做,但它不起作用,因为我必须删除对“BusyIndi​​catorBehaviour”的所有引用,编译,然后重新添加引用。我忘记了 WPF 的“功能”。谢谢你。知道我正在从正确的方向接近,这让我探索了它不起作用的其他原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-10
  • 2011-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-23
相关资源
最近更新 更多