如何防止自定义活动设计器中自动调整大小?
我希望你能帮助我解决我的问题。这是关于 WF 4.0 活动的自定义设计器,但问题本质上出在设计器的 WPF 中。 一些背景
我创建了一个自定义工作流程活动来发送电子邮件。对于活动的自定义设计器,我之前一直使用常规文本框作为电子邮件的“主题”和“正文”,但我想使用 ExpressionTextBox 轻松将其绑定到活动的 InArguments 。 ExpressionTextBox 位于网格中,该网格位于 StackPanel 上。
我已经设置了 ExpressionTextBoxes 的 MinWidth、MaxWidth 和 Margin 以适应其他控件,并且在 Visual Studio 设计器(查看自定义活动设计器,而不是实际的工作流)中,一切看起来都应有的样子。
<sapv:ExpressionTextBox Grid.Column="1" Grid.Row="2" Height="Auto" HorizontalAlignment="Right" Margin="4, 4, 4, 4"
Expression="{Binding Path=ModelItem.Subject, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
ExpressionType="{x:Type TypeName=sys:String}" OwnerActivity="{Binding Path=ModelItem}" VerticalAlignment="Center" MaxWidth="176" MinWidth="175" />
问题
使用时,最初它看起来也应该是这样,但是当编辑 ExpressionTextBox 时,它们会缩小到非常小。输入文本时,控件将展开以适合文本,直到达到其最大宽度。编辑结束后,它会返回到最大宽度。我希望它保持相同的大小,无论是否处于编辑模式。
如果看不到它,请打开图像 此处
我尝试过的内容
我主要使用 WinForms,对 WPF 非常缺乏经验,所以我不知道是否有一些我错过的时髦属性或其他设置。我尝试过设置父控件(StackPanel 和 Grid)的宽度属性,我尝试过仅设置宽度(无最小/最大),但无论我设置什么,它似乎都会缩小。
如果您想了解更多信息或代码,请随时询问。
更新
正如您在 Maurices 回答的评论中看到的,我想出了如何通过删除 HorizontalAlignment 属性,然后使用边距将其向右对齐来避免问题。但在解释这种行为最初发生的原因之前,我不会给出答案。我的 XAML 与莫里斯发布的几乎相同,所以其他地方肯定有问题。
I hope you can help me with my problem. It's about a custom designer for a WF 4.0 activity, but the problem is essentially in the WPF of the designer.
Some background
I've created a custom WorkFlow activity to send e-mails. For the custom designer for the activity, I've previously been using regular Textboxes for the "Subject" and "Body" of the e-mail, but I'd like to use the ExpressionTextBox to easily bind it to the InArguments of the activity. The ExpressionTextBoxes are in a grid, and this grid is on a StackPanel.
I've set the the MinWidth, MaxWidth and Margin of the ExpressionTextBoxes to fit with the other controls, and in the Visual Studio Designer (viewing the custom activity designer, not the actual WorkFlow) everything looks as it should.
<sapv:ExpressionTextBox Grid.Column="1" Grid.Row="2" Height="Auto" HorizontalAlignment="Right" Margin="4, 4, 4, 4"
Expression="{Binding Path=ModelItem.Subject, Mode=TwoWay, Converter={StaticResource ArgumentToExpressionConverter}, ConverterParameter=In}"
ExpressionType="{x:Type TypeName=sys:String}" OwnerActivity="{Binding Path=ModelItem}" VerticalAlignment="Center" MaxWidth="176" MinWidth="175" />
The problem
When used, initially it also looks as it should, but when the ExpressionTextBoxes are edited, they shrink into being really small. When text is entered, the control expands to fit the text, until it reaches its MaxWidth. When the editing ends, it goes back to it's MaxWidth. I'd prefer if it stayed the same size, regardless of being in edit-mode or not.
If you can't see it, open the image here
What I've tried
I've mostly been doing WinForms, and I'm pretty inexperienced with WPF, so I don't know if there are some funky properties or other settings that I've missed. I've tried setting width-properties of the parent controls (StackPanel and Grid), I've tried setting just the width (no min/max), but it seems to shrink regardless of what I set.
If you would like more information or code, please don't hesitate to ask.
Update
As you can see in the comments to Maurices answer, I figured out how to avoid the problem by removing the horizontalAlignment property, and then using margins to align it to the right. But I'm not going to mark an answer, until there's an explanation of why this behaviour happened in the first place. My XAML was almost identical to what Maurice posted, so there must be something wrong elsewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ExpressionTextBox 的 XAML 对我来说看起来很好,当我尝试以下设计器时,它工作得很好。
所以我怀疑问题可能出在你的网格定义中。
The XAML for the ExpressionTextBox looks fine to me and when I try the following designer it works just fine.
So I suspect the problem is possibly in your grid definition.