有没有人知道一些可用的全局状态变量,以便我可以检查代码当前是否在设计模式下执行(例如在Blend或Visual Studio中)?
它看起来像这样:
//pseudo code:
if (Application.Current.ExecutingStatus == ExecutingStatus.DesignMode)
{
...
}
Run Code Online (Sandbox Code Playgroud)
我需要这个的原因是:当我的应用程序在Expression Blend中以设计模式显示时,我希望ViewModel使用"Design Customer类",其中包含模拟数据,设计人员可以在设计模式下查看.
但是,当应用程序实际执行时,我当然希望ViewModel使用返回实际数据的真实Customer类.
目前我通过让设计人员在开始工作之前进入ViewModel并将"ApplicationDevelopmentMode.Executing"更改为"ApplicationDevelopmentMode.Designing"来解决这个问题:
public CustomersViewModel()
{
_currentApplicationDevelopmentMode = ApplicationDevelopmentMode.Designing;
}
public ObservableCollection<Customer> GetAll
{
get
{
try
{
if (_currentApplicationDevelopmentMode == ApplicationDevelopmentMode.Developing)
{
return Customer.GetAll;
}
else
{
return CustomerDesign.GetAll;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我为Button创建了一个Blend行为.如何将其设置为应用程序中的所有按钮.
<Button ...>
<i:Interaction.Behaviors>
<local:MyBehavior />
</i:Interaction.Behaviors>
</Button>
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试:
<Style>
<Setter Property="i:Interaction.Behaviors">
<Setter.Value>
<local:MyBehavior />
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
我收到了错误
"行为"属性没有可访问的setter.
我正在使用Microsoft Expression Blend 4
我有一个浏览器..,
[XAML] ConnectionView"后面的空代码"
<WebBrowser local:AttachedProperties.BrowserSource="{Binding Source}">
<i:Interaction.Triggers>
<i:EventTrigger>
<i:InvokeCommandAction Command="{Binding LoadedEvent}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Navigated">
<i:InvokeCommandAction Command="{Binding NavigatedEvent}" CommandParameter="??????"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</WebBrowser>
Run Code Online (Sandbox Code Playgroud)
[C#] AttachedProperties类
public static class AttachedProperties
{
public static readonly DependencyProperty BrowserSourceProperty = DependencyProperty . RegisterAttached ( "BrowserSource" , typeof ( string ) , typeof ( AttachedProperties ) , new UIPropertyMetadata ( null , BrowserSourcePropertyChanged ) );
public static string GetBrowserSource ( DependencyObject _DependencyObject )
{
return ( string ) _DependencyObject . GetValue ( BrowserSourceProperty …Run Code Online (Sandbox Code Playgroud) 我的意思是,作为一个普通的开发人员,我会用Expression Blend实现一些我不会使用VS的东西吗?我不知道Expression Blend,乍一看看起来不是很友好/容易学习.
你在那里做什么?值得花时间学习使用它,或者我将和VS一样做?
谢谢!
编辑:我知道微软对这些工具的评价.我想知道的是,作为像我这样的开发人员,你是否尝试过Expression Blend并发现这是浪费时间,或者你认为它是一个很好的工具,你停止从VS开发WPF GUI并切换到EB.
我在Expression Blend中使用DataGrid,但我只需要显示注册表并隐藏ColumnHeader.
我怎么做?
这似乎是一个非常非常简单的问题,但我无法弄明白.罪魁祸首似乎是WP7的默认风格.单击按钮时,它会将背景颜色更改为白色,然后返回到按钮的默认背景.
我遇到的问题是我想在单击按钮时更改按钮的背景.我找不到任何可能的方法来做到这一点.
我已经尝试在代码中设置背景,但这没有任何作用.我认为它被默认样式覆盖了.
我尝试在Blend中使用Property Change行为,但结果完全相同.
我已经尝试为按钮创建一个新的可视状态并在点击时进行设置,但这有点儿错误并且我正在处理的按钮数量有很大的开销.此外,它没有用.
我可以在点击事件中设置其他按钮的背景,而不是单击按钮.
这是一个令人讨厌的障碍!我确信这是一行代码的答案.:)
给定Windows Phone 7.1项目中的格式化文本块:
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="DarkGray" VerticalAlignment="Bottom" Margin="0,0,0,8">
<Run Text="total length "/>
<Run Text="{Binding TotalHours}" FontSize="48"/>
<Run Text="h "/>
<Run Text=":" FontSize="48"/>
<Run Text="{Binding TotalMinutes}" FontSize="48"/>
<Run Text="m "/>
</TextBlock>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
它正在VS设计器中正确预览:

它已经在混合中看起来不像我想要的那样:

它看起来就像Blend(好工作Blend团队)在模拟器和真实设备中一样.
什么在8和45之前和之后添加了这些空格?
如何强制我的布局正确显示(如在VS设计器中)?
我正在尝试使用Blend 3.0来编辑包含一些WPF控件的项目.该项目已经从Visual Studio 2008编译并运行良好.
然而,在Blend中,我遇到了一些毫无意义的神秘错误:
例如,我有一个派生自Control的类:
namespace Company.WPFControls.SearchTextBox
{
public class SearchTextBox : Control
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在同一个程序集中的资源中使用它来分配样式:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Company.WPFControls.SearchTextBox"
<Style TargetType="{x:Type local:SearchTextBox}">
...
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
我在Blend中收到以下错误:
名称"SearchTextBox"在命名空间"clr-namespace:Company.WPFControls.SearchTextBox"中不存在.
我已经尝试通过添加指定程序集名称,;assembly=Company.WPFControls但它不会删除错误.
有没有办法解决这个问题,或者至少找出问题的来源?
我试图在ViewModel/Presentation Model忙时触发进度动画.我有一个IsBusy属性,ViewModel被设置为UserControl的DataContext.当IsBusy属性为true时,触发"progressAnimation"故事板的最佳方法是什么?Blend只让med在UserControl级别添加Event-Triggers,我只能在我的数据模板中创建属性触发器.
"progressAnimation"被定义为用户控件中的资源.
我尝试在UserControl上添加DataTriggers作为样式,但是当我尝试启动StoryBoard时,我收到以下错误:
'System.Windows.Style' value cannot be assigned to property 'Style'
of object'Colorful.Control.SearchPanel'. A Storyboard tree in a Style
cannot specify a TargetName. Remove TargetName 'progressWheel'.
Run Code Online (Sandbox Code Playgroud)
ProgressWheel是我试图设置动画的对象的名称,因此删除目标名称显然不是我想要的.
我希望使用数据绑定技术在XAML中解决这个问题,而不必通过代码公开事件和启动/停止动画.
通过工作,我有一个我喜欢的MSDN订阅Visual Studio Premium.然而,我对过去12个月最大的失望是发现我们从顶级订阅中获得第二名并不足以让我获得Sketchflow!
最明显的是,这不是什么亮点,而且我的边缘令人沮丧!我有什么选择?升级到Sketchflow的Ultimate订阅是不可能的.那么,我是否被迫与Blend 3或Purchase Blend 4分开?
如果这不是我应该问的问题,请告知我,我会删除.对于谷歌无法回答的所有问题,我都倾向于默认使用SO而谷歌没有回答这个问题.
expression-blend ×10
wpf ×6
c# ×3
xaml ×2
.net ×1
animation ×1
browser ×1
datagrid ×1
eventargs ×1
expression ×1
layout ×1
silverlight ×1
sketchflow ×1
textblock ×1
windows ×1