对于那些在实际项目中同时使用Expression Blend和Visual Studio的人,请帮助我了解你们如何在日常开发/设计任务中使用Blend和Visual Studio。以下是一个真实场景:
我在Visual Studio中创建了以下简单的WPF应用程序。它显示了一个客户对象列表,其中使用DataTemplate将客户显示在简单的橙色框中。
现在,我想在这个DataTemplate中加入一些华丽效果,使用Expression Blend进行编辑。
我打开Expression Blend中的项目,希望看到可以更改颜色、创建动画及调整大小等功能的橙色框。然而,我在Expression Blend中看到的是完全空白的框。
所以我理解如下:
- Expression Blend似乎无法理解我的数据来自ViewModel,因此不会显示它。这是Blend的限制还是我需要以某种方式更改代码,使Blend能够解释运行时将输出哪些数据? - 我正在使用具有“示例数据”功能的Expression Blend 3。最佳的使用示例数据功能的方法是什么?即使它不能解释C#并理解将从ViewModel属性中输出哪些数据来填充Listbox,我该如何获得一些虚拟数据,以便我可以操作DataTemplate?
XAML:
我在Visual Studio中创建了以下简单的WPF应用程序。它显示了一个客户对象列表,其中使用DataTemplate将客户显示在简单的橙色框中。
现在,我想在这个DataTemplate中加入一些华丽效果,使用Expression Blend进行编辑。
我打开Expression Blend中的项目,希望看到可以更改颜色、创建动画及调整大小等功能的橙色框。然而,我在Expression Blend中看到的是完全空白的框。
所以我理解如下:
- Expression Blend似乎无法理解我的数据来自ViewModel,因此不会显示它。这是Blend的限制还是我需要以某种方式更改代码,使Blend能够解释运行时将输出哪些数据? - 我正在使用具有“示例数据”功能的Expression Blend 3。最佳的使用示例数据功能的方法是什么?即使它不能解释C#并理解将从ViewModel属性中输出哪些数据来填充Listbox,我该如何获得一些虚拟数据,以便我可以操作DataTemplate?
XAML:
<Window x:Class="TestStringFormat234.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="DataTemplateCustomers">
<Border CornerRadius="5" Background="Orange" Padding="5" Margin="3">
<StackPanel Orientation="Horizontal">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1} (hired on {2:MMM dd, yyyy})">
<Binding Path="FirstName"/>
<Binding Path="LastName"/>
<Binding Path="HireDate"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding GetAllCustomers}"
ItemTemplate="{StaticResource DataTemplateCustomers}">
</ListBox>
</Grid>
</Window>
代码后台:
using System.Windows;
using System.Collections.ObjectModel;
using System;
namespace TestStringFormat234
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
DataContext = new CustomerViewModel();
}
}
//view model
public class CustomerViewModel
{
public ObservableCollection<Customer> GetAllCustomers {
get {
ObservableCollection<Customer> customers = new ObservableCollection<Customer>();
customers.Add(new Customer { FirstName = "Jim", LastName = "Smith", HireDate = DateTime.Parse("2007-12-31") });
customers.Add(new Customer { FirstName = "Jack", LastName = "Jones", HireDate = DateTime.Parse("2005-12-31") });
return customers;
}
}
}
//model
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
}