【问题标题】:WPF Popup inside a DataTemplateDataTemplate 中的 WPF 弹出窗口
【发布时间】:2015-01-07 21:00:27
【问题描述】:

我需要一个 DataTemplate 中的 WPF 弹出窗口,如下所示:

<ScrollViewer>
    <ItemsControl ItemsSource="{Binding Collection}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <TextBox Name="MyTextboxBrief" Text="{Binding TextBrief}"/>
                    <Popup PlacementTarget="{Binding ElementName=MyTextboxBrief}" Placement="Center">
                        <TextBox Name="MyTextboxVerbose" Text="{Binding TextVerbose}"/>
                    </Popup>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>

但是,这个 Popup 应该是这样的:

  1. 它必须与相关的 ItemsControl 项一起滚动
  2. 当应用程序窗口最小化时 - 它不应在桌面上保持可见
  3. 它会比 ItemsControl 高,它的内容不能被剪裁,但不能改变 ItemsControl 的高度
  4. 它将比相关的 ItemsControl 项目更宽 - 但它不应将其他 ItemsControl 项目向左或向右移动

我有一种强烈的感觉,我应该以某种方式使用 ComboBox 模板 - 但我不明白如何获得它的 Popup 行为

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

    我认为Popup 不会在这里帮助您,ComboBox 也不会。看看这是否对您有进一步帮助:

    <DataTemplate>
        <Grid>
            <TextBox Name="MyTextboxBrief" Text="{Binding TextBrief}" />
    
    
            <!-- You might want to bind visibility against
                some kind of property -->
            <Canvas >
                <Canvas.RenderTransform>
                     <!--In case you want to move--> 
                    <TranslateTransform Y="-5" />
                </Canvas.RenderTransform>
    
                <Border Width="100" Height="20" Background="Black">
                    <TextBlock Text="Test" />
                </Border>
            </Canvas>
        </Grid>
    </DataTemplate>
    

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 2016-05-10
      • 2020-04-17
      • 2011-09-04
      • 2011-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多