【问题标题】:WPF Popup not auto-sizing properlyWPF Popup 无法正确自动调整大小
【发布时间】: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);
}

最后是弹出窗口。我已经尝试了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>

【问题讨论】:

  • 当时你能解决这个问题吗
  • 嗨 WizLiz。您能否解决此问题?

标签: wpf popup height


【解决方案1】:

您是否尝试过使用

Height="*" 

Width="*"

还是文本框似乎无法适应其内容的问题?

【讨论】:

  • 好吧,我已经考虑过"*" 的值,但这似乎也不起作用。当我尝试Height="*" 时,弹出窗口甚至没有出现。我不知道它是不改变大小的文本框还是弹出窗口本身(或导致问题的边框)。
猜你喜欢
  • 1970-01-01
  • 2017-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多