- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I established a project which contain Revit DockPanel, then I can't change my properties in the ViewModel using the MVVM pattern.
the mvvm framework is provided by Prism,and the dll can be loaded by Revit; HERE is the GUI:
if I push the [TEST] button , the label "02" should become string-value "CLICKED", BUT it's dose not work ;
AND the property [Message] should be the string-value "INIT" at begining , But it dose not;
HOWEVER,If I am use the same code with xaml-Control <Window> , not the <Page>for dockpanel , there is no problem ;
So ,I don't why ,
maybe property not be load to the dockpanel at begining?
maybe some problem happend at setup the dockpanle?
maybe the mvvm can't be used in the xaml<Page> ?
What the problem on earth?
//================================
here is the code:
TemplateCommand.cs
namespace SEPD.Drawing.DockPanel.Demo
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
[Journaling(JournalingMode.UsingCommandData)]
public class TemplateCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication application = commandData.Application;
TemplateView templateView = new TemplateView();
templateView.DataContext = new TemplateViewModel( );
var guid = new Guid("{ED7FB4B6-572A-43B9-A3AB-DCAA251531B7}");
DockablePaneId paneId = new DockablePaneId(guid);
DockablePane pane = application.GetDockablePane(paneId);
pane.Show();
return Result.Succeeded;
}
}
}
TemplateView.xaml
<Page x:Class="SEPD.Drawing.DockPanel.Demo.TemplateView"
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:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:local="clr-namespace:SEPD.Drawing.DockPanel.Demo"
mc:Ignorable="d"
Title="TITLE"
Height="450" Width="500"
d:DesignHeight="450" d:DesignWidth="500">
<Page.Resources>
<ResourceDictionary>
<local:IntBoolConvert x:Key="intBoolConvert"/>
<local:PercentageConverter x:Key="percentageConverter"/>
<Style x:Key="TextBoxStyleBase" TargetType="{x:Type TextBox}">
<Setter Property="TextWrapping" Value="Wrap"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="150"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Margin" Value="2"/>
</Style>
<Style x:Key="ButtonStyleBase" TargetType="{x:Type Button}">
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="30"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="2"/>
</Style>
<Style x:Key="ComboxStyleBase" TargetType="{x:Type ComboBox}">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Margin" Value="5"/>
</Style>
<Style x:Key="LabelStyleBase" TargetType="{x:Type Label}">
<Setter Property="Width" Value="60"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Margin" Value="2"/>
</Style>
</ResourceDictionary>
</Page.Resources>
<TabControl>
<TabItem Header="002">
<Grid>
<StackPanel>
<Button Content="TEST" Command="{Binding TempCommand2 }" Style="{StaticResource ButtonStyleBase}"/>
<Label Content="{Binding Message,FallbackValue=02}" Style="{StaticResource LabelStyleBase}"/>
</StackPanel>
</Grid>
</TabItem>
</TabControl>
</Page>
TemplateView.xaml.cs
namespace SEPD.Drawing.DockPanel.Demo
{
/// <summary>
/// TemplateView.xaml 的交互逻辑
/// </summary>
public partial class TemplateView : Page, IDockablePaneProvider
{
public TemplateView()
{
InitializeComponent();
}
public void SetupDockablePane(DockablePaneProviderData data)
{
data.FrameworkElement = this as FrameworkElement;
data.InitialState = new DockablePaneState();
data.InitialState.DockPosition = DockPosition.Left;
}
}
}
TemplateViewModel.cs
namespace SEPD.Drawing.DockPanel.Demo
{
public partial class TemplateViewModel : BindableBase
{
// cur_DIR
static readonly string assemblyPath = Assembly.GetExecutingAssembly().Location;
static readonly string assemblyDir = Path.GetDirectoryName(assemblyPath) + "\\";
public ICommand TempCommand2 { get; set; }
public TemplateViewModel( )
{
PreProccess();
this.TempCommand2 = new DelegateCommand(()=>{
Message = "CLICKED";
});
}
//property
private string _message = "INIT";
public string Message
{
get => _message;
set => SetProperty(ref _message, value);
}
}
}
Solved! Go to Solution.