我有一个Image在Scrollviewer...
<ScrollViewer x:Name="Scrollster" ZoomMode="Enabled" MinZoomFactor="1" MaxZoomFactor="4"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" ManipulationMode="All">
<Image x:Name="Img" Source="{x:Bind ImgSource}" Stretch="UniformToFill" PointerPressed="Img_PointerPressed"/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
当我用鼠标指针拖动图像时,我想移动图像!
我试过了:
private void Img_PointerPressed(object sender,PointerRoutedEventArgs e)
{
var p = e.Pointer;
}
Run Code Online (Sandbox Code Playgroud)
但我无法获得指针位置来改变scrollviewer位置.
我的代码出了什么问题?我做得对吗?
我正在尝试将 HorizontalAlignment 和 VerticalAlignment 设置为 Center,以便 RelativePanel 正好位于 UWP 应用程序的中间。在RelativePanel 中有子项,子项应该在RelativePanel内居中。它应该看起来像:
如您所见,RelativePanel 位于中间,子项位于彼此之上并居中。我试过这个 XAML 代码:
<RelativePanel x:Name="relativePanel1" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock x:Name="textBlock1" Text="Yo, waddup? Enter your GUID to continue" IsTextSelectionEnabled="True" FontFamily="Chiller" FontSize="72" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBox x:Name="textBox1" AcceptsReturn="True" HorizontalAlignment="Center" InputScope="Text" PlaceholderText="{}{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" RelativePanel.Below="textBlock1" VerticalAlignment="Center" />
</RelativePanel>
Run Code Online (Sandbox Code Playgroud)
这是调试时的样子:
我有一个简单的IMarkupExtension如下:
public class HelloWorldMarkup : IMarkupExtension<string>
{
public string ProvideValue(IServiceProvider serviceProvider)
{
return "Hello World";
}
public override string ToString()
{
return "DesignTime Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
和我这样使用它的Xaml ..
<StackPanel>
<TextBlock Text="{my:HelloWorldMarkup}" />
<HyperlinkButton Content="{my:HelloWorldMarkup}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
在运行时,它都按预期工作.
但是,在设计时,超链接的内容显示设计时间值(来自ToString),但TextBlock的文本不显示.
如果我这样离开,我的设计师会对我抱怨好几天..有没有人对如何在TextBlock Text中显示我的Markups显示设计时间数据有任何建议?
非常感谢,
我想用编译后的绑定将页面中的元素绑定到代码中的依赖项属性,同时用通常的绑定将另一个元素绑定到ViewModel。但这会导致运行时错误。
这是我的xaml代码。
<Page
x:Class="XbindingProblem.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XbindingProblem"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
DataContext="{Binding Main, Source={StaticResource Locator}}"
mc:Ignorable="d">
<Page.Resources>
<DataTemplate x:Key="UserDataTemplate" x:DataType="local:User">
<StackPanel>
<TextBlock Text="{x:Bind Name}" />
<TextBlock Text="{x:Bind Age}" />
</StackPanel>
</DataTemplate>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<TextBlock Text="{Binding Title}"/>
<ContentPresenter ContentTemplate="{StaticResource UserDataTemplate}" Content="{x:Bind CurrentUser, Mode=OneWay}"/>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这里CurrentUser是依赖项属性,该属性最初为null,然后在运行时更改。这给出了以下运行时错误。
Incorrect type passed into template. Based on the x:DataType global::XbindingProblem.User was expected.
Run Code Online (Sandbox Code Playgroud)
问题在于,当CurrentUser为null时,它将ViewModel传递给UserDataTemplate而不是CurrentUser依赖项属性。
谁能对这个问题有一个很好的解释?
在我的UWP中,我正在尝试在Frame的中心打开一个MenuFlyout.
我怎样才能把它放在中心?
我已经尝试过这段代码,但它在框架顶部设置了弹出窗口.
private void ListView_ItemClick(object sender,ItemClickEventArgs e) {
var m = new MenuFlyout();
var t = new MenuFlyoutItem() { Text = "SomeTxt"};
m.Items.Add(t);
m.ShowAt((FrameworkElement)Frame);
}
Run Code Online (Sandbox Code Playgroud)
甚至尝试添加m.Placement = Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Center;但FlyoutPlacementMode枚举不包含Center.
我正在尝试制作一个程序来解析具有预定义格式的xml文件,并将一些UI控件添加到Windows Universal Application中的MainPage中。
在某些部分中,我需要在相关的xml文件中指定TextBlocks的背景颜色,因此我正在寻找一种转换字符串属性,从xml读取并将其转换为Windows.UI.Color对应值的方法。
这是我的xml文件和要添加控件的C#代码
xml:
<test-unit name ="FOG_LAMP" text ="Fog Lamp" mode ="DIG_IN" color="ORANGE"/>
Run Code Online (Sandbox Code Playgroud)
C#:
public void AddNewTextBlock(String Name, String Text, String Color)
{
TextBlock NewTextBlock = new TextBlock();
NewTextBlock.Name = Name;
NewTextBlock.Text = Text;
NewTextBlock.FontSize = 24;
myGrid.Children.Add(NewTextBlock);
}
Run Code Online (Sandbox Code Playgroud)
感谢帮助
我在我的项目中有拥挤的页面,我想在一个页面中放置太多的复选框控件,所以我正在寻找一种调整复选框大小的方法。当我更改复选框的高度和宽度时,其文本的某些部分会消失,换句话说,我需要缩放我的复选框并制作一些小复选框。
"UWP社区工具包"是一个很好的工具. https://github.com/Microsoft/UWPCommunityToolkit/tree/master
但是如果我们用NuGet安装它,我们就无法访问源代码(我想).现在,我只想在此工具包中使用"RadialGauge".我想稍微修改一下"RadialGauge"..然后,我开始在没有NuGet安装的情况下使用RadialGauge和源代码.
这是我的一步.
我用C#VS 2017打开了新的UWP项目.
我将此代码安装到我的"Controls"文件夹中. UWP RadialGauge来源
我做了这个项目.
但没有显示,只打开白色的UWP窗口......为什么?我需要帮助......凭借我糟糕的UWP知识,解决是不可能的......
这是项目文件.
https://www.dropbox.com/s/alvw6wcbiv5itsp/RadialGaugeTest.zip?dl=0
我一直在关注这个问题来制作彩色动画.
我可以创建动画,它运行正常,直到动画再次开始.有一刻,感觉动画已在那里开始/停止片刻.我希望动画能够平滑地运行,以便它不会在颜色中显示任何重新启动的效果.有可能吗?
我使用以下代码:
<Storyboard x:Key="GradientAnimation"
RepeatBehavior="Forever"
Storyboard.TargetName="BackgroundBrush"
SpeedRatio="0.3">
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.Background).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)"
EnableDependentAnimation="True"
BeginTime="-0:0:0.5">
<LinearColorKeyFrame KeyTime="0:0:0" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:1" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:2" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:3" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:4" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:5" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:6" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:7" Value="Red"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames
Storyboard.TargetProperty="(UIElement.Background).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
EnableDependentAnimation="True">
<LinearColorKeyFrame KeyTime="0:0:0" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:1" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:2" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:3" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:4" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:5" Value="Black"/>
<LinearColorKeyFrame KeyTime="0:0:6" Value="Red"/>
<LinearColorKeyFrame KeyTime="0:0:7" Value="Black"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
Run Code Online (Sandbox Code Playgroud)
我在代码隐藏中开始这个动画:
((Storyboard)Resources["GradientAnimation"]).Begin();
Run Code Online (Sandbox Code Playgroud)
也许有某种"缓和"方法混合了动画的开始和停止,因此它看起来像长时间运行的动画一样流畅.有什么建议?
如何使用视觉状态更改对象的Canvas.Zindex?我本以期能够做到这样的事情......
<VisualState x:Name="MyVisualState">
<VisualState.Setters>
<Setter Target="MyObject.Visibility" Value="Visible" />
<Setter Target="MyObject.Background" Value="Transparent" />
<Setter Target="MyObject.Canvas.ZIndex" Value="12" />
</VisualState.Setters>
</VisualState>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我还没有找到任何关于如何做到这一点的例子.有人可以帮忙吗?
uwp ×9
c# ×8
xaml ×6
uwp-xaml ×5
windows-10 ×2
design-time ×1
silverlight ×1
visualstates ×1
windows-8.1 ×1
winrt-xaml ×1
xml ×1