Caliburn Micro绑定儿童对财产的控制

时间:2015-01-27 05:43:13

标签: c# wpf caliburn.micro

我有一个View可以很好地加载Caliburn Micro但是在视图中我有一个SmithHtml编辑器,我需要将BindingContent Dependency属性绑定到。

我有一个组合框,其中包含要编辑的文件列表,在我的视图模型中,每当组合框选择发生更改时,我都会更新当前选定的项目,但SmithHtml编辑器BindingContent永远不会更新。

以下是ViewModel:

    using Caliburn.Micro;
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;

namespace PracticumEmailer.Ui.ViewModels
{

    public class EditTemplatesViewModel : Screen
    {
        private readonly string _templatesPath =
            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                Properties.Settings.Default.TemplateDirectory);
        private readonly BindableCollection<string> _files;

        private string _currentTemplate;
        private string _currentContent;

        [ImportingConstructor]
        public EditTemplatesViewModel()
        {
            var info = new DirectoryInfo(_templatesPath);
            _files =
                new BindableCollection<string>(
                    info.EnumerateFiles("*.html").Select(fi => fi.Name.Remove(fi.Name.IndexOf('.')).ToUpper()));
        }

        public BindableCollection<String> Files { get { return _files; } }

        public String ContentHtml
        {
            get
            {
                return _currentContent;
            }
            set
            {
                _currentContent = value;
                NotifyOfPropertyChange(() => ContentHtml);
            }
        }

        public void OnSelectionChanged(string file)
        {
            _currentTemplate = Path.Combine(_templatesPath, string.Format("{0}.html", file.ToLower()));
            ContentHtml = File.ReadAllText(_currentTemplate);
        }
    }
    }

这是XAML:

    <UserControl x:Class="PracticumEmailer.Ui.Views.EditTemplatesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:htmlEditor="clr-namespace:Smith.WPF.HtmlEditor;assembly=Smith.WPF.HtmlEditor"
             xmlns:cal="http://www.caliburnproject.org"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <DockPanel>
        <StackPanel DockPanel.Dock="Top">
            <ComboBox x:Name="Files" cal:Message.Attach="[Event SelectionChanged] = [Action OnSelectionChanged(Files.SelectedItem)]"></ComboBox>
        </StackPanel>
        <htmlEditor:HtmlEditor BindingContent="{Binding Path=ContentHtml}"></htmlEditor:HtmlEditor>

    </DockPanel>
</UserControl>

这最终起作用了:

<htmlEditor:HtmlEditor BindingContent="{Binding BindingContent, Mode=TwoWay}"></htmlEditor:HtmlEditor>

0 个答案:

没有答案