xamlwinui-3winuiwinui-xaml

WinUI 3 InfoBar Margin Remains Even When Hidden – How to Remove It?


I’m using WinUI 3 with C#. When I set a Margin on an InfoBar, the margin remains even when the InfoBar is hidden. Is there a way to make the margin disappear when the InfoBar is not visible? Or is this not possible?

  <Grid Width="400">
    <StackPanel>
      <TextBlock>Message</TextBlock>
      <InfoBar IsOpen="True" Severity="Error" Margin="0,50,0,0" Message="MessageMessageMessage"/>
      <TextBlock>Message2</TextBlock>
    </StackPanel>
  </Grid>

Solution

  • You can switch switch Visibility like this:

    <StackPanel>
        <TextBlock>Message</TextBlock>
        <InfoBar x:Name="InfoBarControl"
            Margin="0,50,0,0"
            IsOpen="{x:Bind Toggle.IsOn, Mode=OneWay}"
            Message="MessageMessageMessage"
            Severity="Error"
            Visibility="{x:Bind InfoBarControl.IsOpen, Mode=OneWay}" />
        <TextBlock>Message2</TextBlock>
    </StackPanel>