Я попробовал около 15 различных способов сослаться на объект (STATIC), к которому я хочу иметь доступ для управления, ни один из них не сработал. Я попробовал DependencyProperty, ничего не сделал. Я искал на этом сайте большую часть часа, и все ответы - это до смешного раздутая ерунда, которая даже не применима.
Я ожидаю простого и разумного метода привязки статического объекта к экземпляру элемент управления, чтобы у меня был доступ к общедоступным свойствам этого объекта, как это обычно бывает во всем объектно-ориентированном программировании.
Вот код соответствующих файлов:
Аддон.cs
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
//Currently a shell class, will be filled later.
namespace Magian_Launcher.lib.data
{
public class Addon
{
public static Addon example = new Addon("Example Addon", "This is an example addon for testing the UI", "test.example.com", "", "test.example.com");
public string Name { get; set; }
public string Author { get; set; }
public string Description { get; set; }
public string DownloadURL { get; set; }
public string InstallLocation { get; set; }
public string RepoURL { get; set; }
public Addon() { }
public Addon(string name, string description, string downloadURL, string installLocation, string repoURL)
{
Name = name;
Description = description;
DownloadURL = downloadURL;
InstallLocation = installLocation;
RepoURL = repoURL;
}
public void Install()
{
}
public void Uninstall()
{
}
public void Update()
{
}
public override string ToString()
{
return $"{Name}\n{Description}\n{DownloadURL}\n{InstallLocation}";
}
}
}
Код: Выделить всё
Код: Выделить всё
using Magian_Launcher.lib.data;
using MahApps.Metro.ValueBoxes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Magian_Launcher
{
///
/// Interaction logic for AddonControl.xaml
///
public partial class AddonControl : UserControl
{
public AddonControl(Addon content)
{
InitializeComponent();
this.content = content;
this.DataContext = this;
}
public Addon content { get; set; }
public string Title { get { return content.Name; } }
public string Description { get { return content.Description; } }
public string Author { get { return content.Author; } }
public string RepoURL { get { return content.RepoURL; } }
public Boolean AddonEnabled { get; set; }
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... er-control