0

最近、QuickGraph と Graph# を使用して、プラグインとそれらの間の可能な接続のグラフを管理および表示し始めました。

各プラグインは、表示したいプロパティを含む Plugin クラスのオブジェクトによって表されるため、このクラスには DataTemplate を使用しようとしました。

問題は、GraphLayout が表示されているウィンドウが (InitializeComponent 中に) 表示されているときに、明らかにリソース ディクショナリによって XamlParseException がスローされることです。

例外の詳細 (フランス語で申し訳ありません:P):

L'exception System.Windows.Markup.XamlParseException s'est produite   HResult=-2146233087   Message=La propriété Set 'System.Windows.ResourceDictionary.DeferrableContent' a levé une exception.   Source=PresentationFramework   LineNumber=0   LinePosition=0   StackTrace:
       à System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       à System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       à System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       à System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       à IHM.PluginsWindow.InitializeComponent() dans c:\SIMON\Ptiou\IHM\00-SRC\widget\PluginsWindow.xaml:ligne 1
       à IHM.PluginsWindow..ctor() dans C:\SIMON\Ptiou\IHM\00-SRC\widget\PluginsWindow.xaml.cs:ligne 35   InnerException: System.NotImplementedException
       HResult=-2147467263
       Message=La méthode ou l'opération n'est pas implémentée.
       Source=PresentationFramework
       StackTrace:
            à System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId)
            à System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
            à System.Windows.Baml2006.Baml2006Reader.Process_ConstructorParameterType()
            à System.Windows.Baml2006.Baml2006Reader.Process_OneBamlRecord()
            à System.Windows.Baml2006.Baml2006Reader.ReadKeys()
            à System.Windows.ResourceDictionary.SetDeferrableContent(DeferrableContent deferrableContent)
            à System.Windows.Baml2006.WpfSharedBamlSchemaContext.<>c.<Create_BamlProperty_ResourceDictionary_DeferrableContent>b__297_0(Object target, Object value)
            à System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(Object instance, Object value)
            à MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
            à MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
       InnerException:

問題はおそらく、私が使用している DataTemplate から来ているに違いありません。これがなくても、グラフは正常に表示されているためです (ただし、オブジェクトのプロパティを表示することはできません)。また、バインディングまたはコードビハインドからグラフを設定しようとしましたが、何も変わりませんでした。

GraphLayout と DataTemplate がある XAML ファイル:

<Window x:Class="IHM.PluginsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpfextensions="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        xmlns:datamodel="clr-namespace:DATAMODEL;assembly=DATAMODEL"
        xmlns:local="clr-namespace:IHM"
        Height="1080" Width="1920" Margin="0,0,0,0"
        Topmost="true" ResizeMode="NoResize" WindowStyle="None" ShowInTaskbar="False"   
        WindowStartupLocation="Manual"       
        VerticalAlignment="Top"
        HorizontalAlignment="Left"
        AllowsTransparency="True" Background="Transparent"
        WindowState="Normal"
        x:Name="root">


    <Grid Name="containerGrid" Height="1080" Width="1920" Margin="0,0,0,0">
        <Grid.Resources>
            <DataTemplate DataType="{x:Type datamodel:Plugin}">
                <Border BorderThickness="3" CornerRadius="6" Padding="3" BorderBrush="Black">
                    <Grid>
                        <TextBlock Text="{Binding name}"/>
                    </Grid>
                </Border>
            </DataTemplate>
        </Grid.Resources>

        <wpfextensions:ZoomControl>
            <local:MyGraphLayout
                x:Name="pluginGraphLayout"
                LayoutAlgorithmType="FR"
                OverlapRemovalAlgorithmType="FSA"
                HighlightAlgorithmType="Simple">
            </local:MyGraphLayout>
        </wpfextensions:ZoomControl>

    </Grid>

</Window>

コードビハインド:

namespace IHM 
{
    public partial class PluginsWindow : Window, INotifyPropertyChanged
        {
            Point m_start;
            Vector m_startOffset;
            BidirectionalGraph<Plugin, BBlink> pluginGraph = new BidirectionalGraph<Plugin, BBlink>();

            List<Plugin> shownPlugins = new List<Plugin>();
            List<BBlink> shownLinks = new List<BBlink>();

            public PluginsWindow()
            {
                InitializeComponent();
                this.Background = new SolidColorBrush(Color.FromArgb(255, 140, 140, 140));
            }

            public void MakeGraph(List<BBlink> links)
            {
                List<Plugin> plugins = new List<Plugin>();
                foreach(BBlink link in links)
                {
                    if(!plugins.Contains(link.startPlugin))
                        plugins.Add(link.startPlugin);
                    if(!plugins.Contains(link.endPlugin))
                        plugins.Add(link.endPlugin);
                }
                if(plugins.Count < 1)
                    return;

                this.shownPlugins = plugins;
                this.shownLinks = links;
                this.showPathGrid();

                BidirectionalGraph<Plugin, BBlink> graph = new BidirectionalGraph<Plugin,BBlink>();
                foreach (Plugin plugin in plugins)
                    graph.AddVertex(plugin);

                foreach (BBlink link in links)
                    graph.AddEdge(link);

                this.pluginGraph = graph;
                this.pluginGraphLayout.Graph = graph;
            }

            protected void OnPropertyChanged(string propertyName)
            {
                var handle = PropertyChanged;
                if (handle != null)
                    handle(this, new PropertyChangedEventArgs(propertyName));
            }

            public event PropertyChangedEventHandler PropertyChanged;
        }

        public class MyGraphLayout : GraphSharp.Controls.GraphLayout<Plugin, BBlink, IBidirectionalGraph<Plugin, BBlink>>
        { /* nothing to do here... */ }
}

Graph# ドキュメントが完全に存在しないことはまったく役に立たなかったので、彼らのサイトでこの投稿をたどってみましたが、私が行ったことと同じように見えます。

4

1 に答える 1