开发者

Problems with using Controls.Popup as error adorner in WPF

My (simplified) validation template is

<Grid>
  <Border x:Name="ErrorAdorner" 
          BorderBrush="Red">
    <AdornedElementPalceHolder />
  </Border>
  <Popup x:Name="ErrorPopup"
         PalcementTarget="{Binding ElementName=ErrorAdorner}"
         Placement="Bottom"
         StaysOpen="false"
         IsOpen="true">
    <Grid>
      <TextBloxk Text="Error!!!" />
    </Grid>
  </Popup>
</Grid>

The adorned element is typically a textbox

The problem I have with this approach is that, as soon as I click inside the textbox, the ErrorPopup disappears and the ErrorAdorner remains visible. Desired behavior is that both should stay visible.

Things tried:

  1. Set StaysOpen to true on ErrorPopup. Problem: when you resize/move the parent window when the error is visible, the ErrorPopup remains at the same location, it doesnt move along with the textbox
  2. Use a StackPanel around the textbox (adorned element) and the error message text block. Problem: Popup comes with positioning capabilities ie., if there is not enough screen area below the textbox for the adorner, it automatically relocates it. But if a stack panel is used, error message just cuts off if there is no space or it changes the textbox layout(not desired)

So in essence, I want to use the popup for its 开发者_运维问答positional capabilities, but somehow want to fix the visibility problem


The problem here is that you can resize the window even if the cursor is inside the TextBox, you cannot get any useful state information out of that, so if you make the IsOpen dependent on that you still get dislocated popups.

Possibly this related question can help you with the placement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜