- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为删除 的按钮。我只想在满足某些条件时才可见,那我该怎么做呢??
创建按钮的 XAML 代码是
<Button x:Name="DeleteButton" Content="Delete" HorizontalAlignment="Left" Height="64" Margin="74,579,0,-9" VerticalAlignment="Top" Width="314" FontSize="24"/>
最佳答案
你有一个 Visibility 属性。
你有一些方法可以做到:
就在后面的代码中,您应该:
if (condition)
{
DeleteButton.Visibility = Visibility.Visible; //Also possible to Collapse (hide).
}
上面的代码应该可以帮助您分别使按钮不可见和可见。
注意:这是不太可取的,它不是动态的,会导致重复和不必要的代码。
更好和更动态的方法是:
您可以创建一个 bool 属性并将可见性按钮绑定(bind)到它,如下所示:
bool IsVisible { get; set; } //Code behind
在 xaml 中:
<!-- Pay attention: The Converter is still not written, follow next steps -->
<Button x:Name="DeleteButton"
Content="Delete"
HorizontalAlignment="Left" Height="64" Margin="74,579,0,-9"
VerticalAlignment="Top" Width="314" FontSize="24"
Visibility="{Binding IsVisible,
Converter={StaticResource BooleanToVisibilityConverter}}" />
转换器:
public class BooleanToVisibilityConverter : IValueConverter
{
/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>A converted value. Returns Visible if the value is true; otherwise, collapsed.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture)
{
throw new NotImplementedException();
}
}
并且在 xaml 中的资源中,您应该添加转换器,以便您可以使用 StaticResource 访问它:
<Application
x:Class="UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:UI.Converters">
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
然后根据需要更改 IsVisible 属性,如果为 true,它将绑定(bind)到 Visible,如果为 false,它将被折叠。
if (condition)
{
IsVisible = true;
}
更多信息你应该学习:binding , converters .
关于c# - 如何使按钮以编程方式在 Windows Phone 中可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19582801/
我开发了一个使用 mspn 服务的 windows phone 应用程序。它在 Windows 手机模拟器上运行良好。现在我想在 Windows Phone 设备中测试它。我有一个 Windows P
我正在考虑针对 Windows Phone 7 进行开发。为了测试我的应用程序,我需要能够模拟电话调用。在模拟器中可以吗? 最佳答案 不,不可能模拟您的应用程序被接收到的电话中断。还宣布为 the R
我看到 Windows Phone 8 支持 Windows Phone 7 应用程序。我在 Windows Phone 7 上开发了一些应用程序,我想在 Windows Phone 8 模拟器上运行
我正在Windows 8上使用Visual Studio2013。我有三个Windows Phone设备,lumia 620、920、1320,这些都是开发人员解锁的设备。 620设备已安装Windo
非常直接的问题。我的公司开发了一个 windows phone 7 应用程序,并一直在 windows phone 7 设备上对其进行测试。我们能否安全地假设同一个应用程序将向后兼容并在 Window
标题几乎概括了它。我已经编写了一个 Windows Phone 7 应用程序,现在我想将它部署到 Windows Phone 8 设备 (HTC Windows Phone 8X)。我已经注册并解锁了
我一直在开发 Windows Phone 8 应用程序,现在我想将其更改为 Windows Phone 8.1。我该怎么做? 是否应该创建一个新的 Windows Phone 8.1 应用并将所有现有
我有一个针对 Windows Phone 8 的应用程序。现在我想使用 this compression library其中指出: Supported Platforms: .NET Framewor
有什么区别Windows Phone 7.1 (NoDo) 和 Windows Phone 7.5 (芒果) ? 我已经为 Mango 安装了 SDK,但是当我尝试创建一个项目时,它显示为 7.1 版
我最近更新了我的 Visual Studio 2013,现在它允许开发 Windows Phone 8.1 应用程序。 但是现在,当我创建一个 Windows Phone 项目时,它是针对 WP 8.
我最近购买了 Lumia 630 双 SIM 卡,并一直在尝试注册我的手机以进行开发,但一直收到此错误“无法连接到手机。请确保通过 USB 传输服务的 Windows Phone IP 正在运行”。
我正在尝试使用 documentation from MSDN 在我现有的 Windows Phone OS 7.1 应用程序中支持新的 Windows Phone 磁贴功能。 .但是,我似乎无法通过
我在搜索如何启动Windows Phone 10模拟器时迷路了。 我已经做了: 我下载并安装了仿真器镜像(我知道flash.vhd文件的位置) 我正在运行Windows 8.1 x64专业版。 Hyp
我想制作像图片一样的动态磁贴。我该怎么做? 最佳答案 上面创建的图 block 很可能是在服务器端创建的。据说 Windows Phone 7.1 和 Windows Phone 8 之间发生了很多变
我刚刚将它安装在我的 Windows 8 上。它不是在 VM 上运行,而是在带有 bootcamp 的 macbook 上运行。 当我尝试模拟我的应用程序时,出现第一个错误: 但是后来我单击“重试”并
Microsoft 刚刚发布了结合了 Windows 8.1 和 Windows Phone 8.1 的 Windows App 8.1,因此您可以创建一个通用的应用程序。但是,将 Microsoft
是否有可用于WP7的日历控件(不是日期选择器和时间选择器)? 最佳答案 我还在CodePlex上启动了新项目。我刚刚研究了日历控件的Alpha版本。 http://wpcontrols.codeple
我在XAML中有一个文本框: .cs文件声明了以下事件: private void blah_OnKeyDown(object sender, KeyEventArgs e) {
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我正在为Windows Phone 7创建一个多人游戏。如何调试模拟器的多个实例以便对其进行调试? 最佳答案 实际上,您可以同时运行Windows Phone 7模拟器的多个实例,甚至可以同时调试它们
我是一名优秀的程序员,十分优秀!