programing

다른 모든 컨트롤보다 오버레이 컨트롤을 우선시하는 방법은 무엇입니까?

closeapi 2023. 5. 6. 15:00
반응형

다른 모든 컨트롤보다 오버레이 컨트롤을 우선시하는 방법은 무엇입니까?

컨트롤을 다른 모든 컨트롤 위에 표시해야 합니다. 그러면 컨트롤이 부분적으로 오버레이됩니다.

를 사용하는 경우Canvas또는Grid레이아웃에서 맨 위에 놓을 컨트롤을 더 높게 지정합니다.ZIndex.

MSDN에서:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="ZIndex Sample">
  <Canvas>
    <Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="100" Canvas.Left="100" Fill="blue"/>
    <Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="150" Canvas.Left="150" Fill="yellow"/>
    <Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="200" Canvas.Left="200" Fill="green"/>

    <!-- Reverse the order to illustrate z-index property -->

    <Rectangle Canvas.ZIndex="1" Width="100" Height="100" Canvas.Top="300" Canvas.Left="200" Fill="green"/>
    <Rectangle Canvas.ZIndex="3" Width="100" Height="100" Canvas.Top="350" Canvas.Left="150" Fill="yellow"/>
    <Rectangle Canvas.ZIndex="2" Width="100" Height="100" Canvas.Top="400" Canvas.Left="100" Fill="blue"/>
  </Canvas>
</Page>

지정하지 않은 경우ZIndex패널의 하위 항목이 지정된 순서대로 렌더링됩니다(예: 맨 위의 마지막 항목).

만약 당신이 더 복잡한 일을 하고 싶다면, 당신은 어떻게 해야 하는지 볼 수 있습니다.ChildWindow은 Silverlight에서 구현됩니다.반투명 배경과 팝업이 전체에 걸쳐 표시됩니다.RootVisual.

로버트 로스니는 좋은 해결책을 가지고 있습니다.여기 제가 과거에 사용했던 다른 솔루션이 있습니다. "Overlay"와 나머지 콘텐츠를 구분합니다.이 솔루션은 연결된 속성을 활용합니다.Panel.ZIndex다른 모든 것 위에 "오버레이"를 배치합니다.코드에서 "오버레이"의 가시성을 설정하거나 다음을 사용할 수 있습니다.DataTrigger.

<Grid x:Name="LayoutRoot">

 <Grid x:Name="Overlay" Panel.ZIndex="1000" Visibility="Collapsed">
    <Grid.Background>
      <SolidColorBrush Color="Black" Opacity=".5"/>
    </Grid.Background>

    <!-- Add controls as needed -->
  </Grid>

  <!-- Use whatever layout you need -->
  <ContentControl x:Name="MainContent" />

</Grid>

그리드의 동일한 셀에 있는 컨트롤은 앞뒤로 렌더링됩니다.하나의 컨트롤을 다른 컨트롤 위에 올려놓는 간단한 방법은 같은 셀에 넣는 것입니다.

다음은 장기 실행 작업이 실행되는 동안(즉, 사용자 컨트롤) 사용 중인 메시지와 함께 보기의 모든 항목(즉, 사용자 컨트롤)을 비활성화하는 패널을 팝업하는 유용한 예입니다.BusyMessage바인딩된 속성이 null이 아닙니다):

<Grid>

    <local:MyUserControl DataContext="{Binding}"/>

    <Grid>
        <Grid.Style>
            <Style TargetType="Grid">
                <Setter Property="Visibility"
                        Value="Visible" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding BusyMessage}"
                                 Value="{x:Null}">
                        <Setter Property="Visibility"
                                Value="Collapsed" />
                    </DataTrigger>

                </Style.Triggers>
            </Style>
        </Grid.Style>
        <Border HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="DarkGray"
                Opacity=".7" />
        <Border HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Background="White"
                Padding="20"
                BorderBrush="Orange"
                BorderThickness="4">
            <TextBlock Text="{Binding BusyMessage}" />
        </Border>
    </Grid>
</Grid>

xaml 코드 끝에 가져올 컨트롤을 앞에 놓습니다.예.

<Grid>
  <TabControl ...>
  </TabControl>
  <Button Content="ALways on top of TabControl Button"/>
</Grid>

이것은 WPF에서 아도르의 일반적인 기능입니다.장식은 일반적으로 다른 모든 컨트롤 위에 나타나지만 z-order를 언급하는 다른 답변이 사용자의 경우에 더 적합할 수 있습니다.

<Canvas Panel.ZIndex="1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="570">
  <!-- YOUR XAML CODE -->
</Canvas>

언급URL : https://stackoverflow.com/questions/5450985/how-to-make-overlay-control-above-all-other-controls

반응형