[英]WPF Popup not auto-sizing properly
我有一個彈出窗口,應該顯示錯誤。 此彈出窗口顯示一個TextBlock,該文本綁定到字段ErrorMessage。 由於我的錯誤消息正確更新,因此綁定顯然可以正常工作。 但是,當消息太長時,彈出窗口的高度不會改變,並且錯誤消息的某些部分仍處於隱藏狀態。 我確定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>
您是否嘗試過使用
Height="*"
和
Width="*"
還是問題似乎不適合其內容的文本框?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.