我CommandBar在XAML中将其IsOpen属性设置为true,因此每个按钮的文本都是可见的,因为我希望描述保持可见.
当我点击省略号按钮时,它会隐藏文本,第二次点击它时,我收到以下错误:
No installed components were detected. Cannot resolve TargetName HighContrastBorder.
用户界面有些尴尬,可能与此有关,但我无法弄清楚是什么或为什么:
正如您所看到的,我正在显示的各种按钮的按钮文字被截断:
代码方面,据我所知,它并没有什么特别之处:
<Page.BottomAppBar>
<CommandBar IsOpen="True"
ClosedDisplayMode="Compact"
IsSticky="True"
Visibility="{Binding
CommandBarViewModel.IsCommandBarVisible,
Converter={StaticResource BoolToVisibilityConverter}}"
Background="{ThemeResource SystemControlBackgroundAccentBrush}">
<AppBarButton
Icon="Add"
Label="Add"
Foreground="White"
Command="{Binding CommandBarViewModel.AddCommand}"
Visibility="{Binding CommandBarViewModel.IsAddVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
<AppBarButton
Icon="Refresh"
Label="Refresh"
Foreground="White"
Command="{Binding CommandBarViewModel.RefreshListCommand}"
Visibility="{Binding
CommandBarViewModel.IsRefreshListVisible,
Converter={StaticResource BoolToVisibilityConverter}}"/>
</CommandBar>
</Page.BottomAppBar>
Run Code Online (Sandbox Code Playgroud)
没有InnerException,App.gics抛出异常
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached)
global::System.Diagnostics.Debugger.Break();
};
#endif
Run Code Online (Sandbox Code Playgroud)
关于我的问题的任何想法,即文本截止和未处理的异常?
谢谢
更新 - 1:
当我CommandBarViewModel.IsCommandBarVisible从Visible属性中删除binded属性()CommandBar并将其硬编码到时Visible,错误向下移动,而不是发生在App.gics中,它现在发生了它试图设置的第一个按钮的binded属性对...的可见度 …
我一直在仔细搜索网络,以获取有关此方面的任何指导,讨论或经验,我认为我可以肯定地说没有任何东西。
我们正在为UWP开发一套控件,我们计划将其开源并免费提供。我们正在构建的控件之一是TimeSpanPicker控件,其外观和行为本质上与TimePicker控件类似,但是它不仅限于一天中的某个时间(即24小时间隔),还允许用户编辑任意内容TimeSpan。
通过使用内置TimePicker控件作为参考,从Windows Runtime API的可见元数据中整理出的内容,使我意识到涉及以下类型的组件:
ControlPickerFlyoutBaseControl我意识到我需要模仿这种模式并为选择器控件编写这三个组件,但是我找不到有关这些组件如何组合在一起的信息,仅凭API表面,我认为不可能弄清楚。
具体来说,我想了解的主要内容是:
TimePickerFlyout纳入TimePicker班级?我在选择器控件的默认模板内的任何地方都看不到弹出按钮的引用。TimePickerFlyoutPresenter控制播放,以及它是如何并入TimePickerFlyout类?本TimePickerFlyout类没有模板-那么它是如何实例化和与通信TimePickerFlyoutPresenter控制?ShouldShowConfirmationButtons和OnConfirmed虚拟方法的预期用途是PickerFlyoutBase什么?当我在具体的实现中覆盖它们时,就永远不会调用它们。如有任何指导,我将非常感谢!
我的XAML UI中有动态添加的控件.如何找到具有名称的特定控件.
我希望能够定义样式并在图标上(或在包含图标的按钮上)设置样式.
设置按钮h/w不会放大符号并添加Viewbox,但我无法弄清楚如何从样式中设置它.
<Button x:Name="ZoomInButton" Style="{ThemeResource HeaderButtonStyle}" Grid.Column="1" Grid.Row="0" Click="ZoomInButton_Click">
<SymbolIcon Symbol="ZoomIn" />
</Button>
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助!看起来很简单,但我很难过!
我有一个文本块列表,可能包括内部网址,如下:
我需要在UWP应用程序中显示此(无限)列表.考虑到此列表可以在应用程序内的多个视图中使用,我将其作为一个通用模板:
<ResourceDictionary>
<ControlTemplate x:Key="ListItemTemplate" TargetType="ItemsControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding image_url}"/>
<TextBlock Grid.Column="1" Text="{Binding status}"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
在此模板中,链接被视为常规文本(预期).据我所知,要使链接工作,我需要将它们包装成<HyperLink>标记,但我不能在模板中执行此操作,因为我不知道链接的确切位置以及将显示多少链接.
有没有办法实现一些渲染器方法,可以<TextBlock>在代码中生成项的body(),处理传递的值?
可能转换器可以帮助我,但如果我理解正确,它只接受绑定的值,我需要引用整个实例.
UPD:从接受的答案中扩展解决方案:
资源字典:
<ResourceDictionary xmlns:resources="using:NamespaceWithTextBlockExt">
<ControlTemplate x:Key="ListItemTemplate" TargetType="ItemsControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding image_url}"/>
<TextBlock Grid.Column="1" resources:TextBlockExt.XAMLText="{Binding Text}"/>
</Grid>
</ControlTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
处理器中某处的处理器:
public static class TextBlockExt
{
public static String GetXAMLText(TextBlock obj)
{ …Run Code Online (Sandbox Code Playgroud) 我在我的UWP应用程序中使用自定义themedictionary.我在运行时更改了ThemeResource的值.此更改仅反映在主视图中,而不反映在其他视图中.即使我在更改资源的值后创建新视图,新视图也只使用资源的初始值.有什么我做错了吗?
这就是我改变资源价值的方式.
(Application.Current.Resources["BackgroundBrush"] as SolidColorBrush).Color = Windows.UI.Colors.Black;
Run Code Online (Sandbox Code Playgroud)
我的次要视图的XAML:
<Grid Background="{ThemeResource BackgroundBrush}"/>
Run Code Online (Sandbox Code Playgroud)
甚至我的主视图都有相同的XAML.
这是完整的项目.下载Repo作为zip
我必须在uwp应用程序中缩放图像,它工作正常,但设计需要在它前面有另一个图像(用作按钮),我也不希望该元素也被缩放.它必须只是canvas标签内的图像,这就是我现在拥有它的方式.
<ScrollViewer MinZoomFactor="1"
ZoomMode="Enabled"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<RelativePanel HorizontalAlignment = "Stretch" >
<Canvas x:Name="canvas">
<Image Source = "{Binding Test,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
</Canvas >
<Button RelativePanel.AlignTopWithPanel="True"
Height="55"
Command="{Binding Path=CollapseSplitView}"
CommandParameter="{Binding ElementName=SplitV}">
<Button.Background>
<ImageBrush ImageSource = "/Assets/btlist.png" ></ ImageBrush >
</Button.Background >
</Button >
<Image RelativePanel.AlignBottomWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Source="/Assets/escala-x.png"
Width="130"
Height="70"
Margin="0,0,20,0"
ScrollViewer.IsZoomChainingEnabled="False"
ScrollViewer.IsZoomInertiaEnabled="False">
</Image>
</RelativePanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
这就是我拥有的xaml,它使缩放适用于其中的所有元素.我试图为不在画布中但没有运气的元素设置scrollViewer.zoomMode = disabled.有任何想法吗?谢谢!
我没有使用该SelectedItem属性Combobox.项目已正确绑定并显示,但无法更改为其他项目.如果尝试选择其他项目,则项目列表将正确关闭,但SelectedItem不会被调用(也不会设置为setter或getter),并且不会更改显示的所选项目.
我的XAML如下:
<ComboBox
ItemsSource="{Binding PasswordTypes}"
ItemTemplate="{StaticResource PasswordTypeTemplate}"
SelectedItem="{Binding SelectedPasswordType, Mode=TwoWay}"
/>
Run Code Online (Sandbox Code Playgroud)
相关ViewModel代码:
public MyViewModel()
{
//these are the only two assignments in code of those two properties
_passwordTypes = new ObservableCollection<PasswordType>(nonEmptyList);
_selectedPasswordType = PasswordTypes.First();
}
private PasswordType _selectedPasswordType;
public PasswordType SelectedPasswordType
{
get => _selectedPasswordType;
set => Set(ref _selectedPasswordType, value);
}
private ObservableCollection<PasswordType> _passwordTypes;
public ObservableCollection<PasswordType> PasswordTypes
{
get => _passwordTypes;
set => Set(ref _passwordTypes, value);
}
Run Code Online (Sandbox Code Playgroud)
两个属性的调用如下:
get PasswordTypes 起源于 this.InitializeComponent() …我有一个新的哲学问题,旨在强调旧的WPF模式与新的UWP模式之间的差异。
我想在UWP环境而不是WPF中扩展具有新属性的标准控件(例如Button)。
在WPF中,我注意到可以用两个文件创建一个自定义控件:一个Themes / Generics.xaml和一个MyCustomControl.cs。
在UWP中,它仅创建.cs文件...是否表示如果我甚至想修改Button的XAML内容(也就是说,我想创建一个IconButton:一个内容为SymbolIcon和Textblock),那不可能吗?
我知道我可以使用“用户控件”,但是它是一个通用控件,我会放开要自定义的控件的所有属性(例如,在我的情况下,是Click事件等)...我甚至可以扩展用户控件以包括所需控件的所有属性...,但这将花费太长时间。
直截了当:在UWP环境中,通过代码AND Xaml定制和扩展标准XAML控件的最佳和正确方法是什么?
例如,考虑一个经典的任务:创建一个IconButton,就像我上面所说的...带有它的Content的Button成为一个带有SymbolIcon和Textblock作为子元素的网格。
谢谢。