2015-07-21 163 views
0

我有一个Popup应该显示错误。此弹出窗口显示绑定到字段ErrorMessage的TextBlock。绑定显然工作正常,因为我的错误消息正确更新。但是,当消息太长时,弹出窗口的高度不会改变,并且错误消息的某些部分仍然隐藏。我确信WPF Popup会自动调整其大小,但在这种情况下,我似乎无法使其工作。WPF Popup不能自动调整大小

错误消息声明如下:

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); 
} 

,最后弹出。我尝试了各种属性HeightWidth的组合。我似乎无法弄清楚如何使这个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> 
+0

你是否能够在当时解决这个问题 – puneet

回答

0

您是否尝试过使用

Height="*" 

Width="*" 

或者是问题这似乎并不适应其内容的文本?

+0

嗯,我已经考虑过值'“*”'但是这似乎也不起作用。当我尝试'Height =“*”'时,弹出窗口甚至不显示。我不知道它的文本框不会改变大小或弹出本身(或导致问题的边界)。 – WizLiz