- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我遇到了一个问题,我需要在 ListBox 中命名一个 UIElement,但我不能这样做,因为它会循环并且显然不能让一百万个小 TextBlock 以相同的名称运行.
这是我的 ListBox 的简化版本:
<ListBox Background="Transparent">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<RelativePanel">
<TextBlock FontSize="12" Text="{Binding Path=Hub}" FontWeight="Bold" Name="firstText" />
<TextBlock FontSize="12" Text="{Binding Path=Stats.Pages}" Name="secondText" RelativePanel.RightOf="firstText" />
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1100" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="secondText.(RelativePanel.RightOf)" Value="hubText" />
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="secondText.(RelativePanel.Below)" Value="firstText" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</RelativePanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
对于我的情况,我尝试在 RelativePanel 上使用 AdaptiveTriggers 以在屏幕较宽时将 secondText
TextBlock 的位置设置到 firstText
的右侧,当屏幕较小时在下方。
据我所知,我可以更改它的唯一方法是在名称上使用 Setter,所以我需要一个独特的方法吗?有更好的方法吗?
编辑: 好的,所以它编译并运行良好(RelativePanel.RightOf 最初工作),但 AdaptiveTriggers 不起作用,VS 对标记提出了质疑。我能做什么?
最佳答案
诀窍是用 UserControl
将元素包装在 DataTemplate
中。
<ListBox.ItemTemplate>
<DataTemplate>
<UserControl>
<RelativePanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="1100" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="secondText.(RelativePanel.RightOf)" Value="hubText" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Normal">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="secondText.(RelativePanel.Below)" Value="firstText" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TextBlock FontSize=" 12" Text="hub" FontWeight="Bold" x:Name="hubText" />
<TextBlock FontSize="12" Text="first" x:Name="firstText" RelativePanel.RightOf="hubText" />
<TextBlock FontSize="12" Text="second" x:Name="secondText" RelativePanel.RightOf="firstText" />
</RelativePanel>
</UserControl>
</DataTemplate>
</ListBox.ItemTemplate>
请注意,我还将 TextBlock
的 Name
更改为 x:Name
。
关于c# - 列表框内元素的唯一名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32292155/
我正在尝试将按钮和 div 底部的一些文本对齐,就像下面的示例中的价格和 checkout 按钮一样。最好的方法是什么。我制作了一个 div,对其设置了样式以获得正确的文本和图片。我只需要将按钮附加到
将内容放置在带圆 Angular 的框 div 中以使其不会重叠的正确方法是什么? 蓝框是白框父div 里面的内容div。我希望标题位于该父框内,以便它在顶部也有圆 Angular 。 当我尝试“溢出
让 SVG 内联 HTML 文档,带有一个 View 框“x y w h”。如何检查元素是否在 View 框内? 通过说元素,它可以是组内的嵌套子路径等等...... 所以我想我正在寻找 SVG 的内
有没有办法检查鼠标是否在屏幕上的某个框内。我不知道将 jQuery 变量导出为整数以在 Javascript if 语句 中使用。我知道这可以通过 div 实现,但我不想使用 div 因为我需要很多这
目前我有两个带文本的 div 框 1 和 2,在第三个 div 框内将它们包含在一起。 Sometimes text in box 1 is longer than text inside box2
我是一名优秀的程序员,十分优秀!