【发布时间】:2015-10-10 20:25:33
【问题描述】:
我有一个应该显示错误的弹出窗口。此弹出窗口显示绑定到字段 ErrorMessage 的 TextBlock。由于我的错误消息正确更新,绑定显然可以正常工作。但是,当消息太长时,弹出窗口的高度不会改变,并且错误消息的某些部分仍然隐藏。我确信 WPF 弹出窗口会根据其内容自动调整其大小,但是在这种情况下,我似乎无法使其正常工作。
错误信息声明如下:
private String _errorMessage;
public String ErrorMessage
{
get { return _errorMessage; }
set
{
_errorMessage = value;
OnPropertyChanged();
}
}
在函数FindErrorInDates()中改变了它的值:
public void FindErrorInDates()
{
this.ErrorCount = 0;
this.HasError = false;
List<String> errors = new List<String>();
if (this.OutwardDeparturePlannedDate >= this.OutwardArrivalPlannedDate)
{
this.ErrorCount += 1;
errors.Add("Outward : Departure must be before Arrival");
}
if (this.ReturnDeparturePlannedDate >= this.ReturnArrivalPlannedDate)
{
this.ErrorCount += 1;
errors.Add("Return : Departure must be before Arrival");
}
if (this.OutwardDeparturePlannedDate >= this.ReturnDeparturePlannedDate
|| this.OutwardDeparturePlannedDate >= this.ReturnArrivalPlannedDate
|| this.OutwardArrivalPlannedDate >= this.ReturnDeparturePlannedDate
|| this.OutwardArrivalPlannedDate >= this.ReturnArrivalPlannedDate)
{
this.ErrorCount += 1;
errors.Add("Conflict between Outward Date and Return Date");
}
this.HasError = this.ErrorCount > 0;
this.ErrorMessage = String.Join("\r\n", errors);
}
最后是弹出窗口。我已经尝试了Height 和Width 的所有属性组合。我似乎无法弄清楚如何使此 ErrorMessage 正确适合 200 宽度的弹出窗口。我错过了什么?
<Popup Height="Auto" IsOpen="{Binding IsMouseOver, ElementName=ValidDepartureDate, Mode=OneWay}" PopupAnimation="None" Placement="Bottom" AllowsTransparency="True">
<Border Height="Auto" Width="200" CornerRadius="2" Padding="5" Background="DarkRed" Visibility="{Binding DataContext.List.Presenter.JourneyResUtility.ErrorCount, Converter={StaticResource ZeroToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=UserControl}}">
<TextBlock Height="Auto" Margin="5" Style="{StaticResource SmallFontStyle}" Text="{Binding DataContext.List.Presenter.JourneyResUtility.ErrorMessage, RelativeSource={RelativeSource AncestorType=UserControl}}" TextWrapping="Wrap"></TextBlock>
</Border>
</Popup>
【问题讨论】:
-
当时你能解决这个问题吗
-
嗨 WizLiz。您能否解决此问题?