小编Muh*_*mar的帖子

如何实现BoolToVisibilityConverter

在我的应用程序中,我想切换StackPanel中项目的可见性.我的Stackpanel包含一个Image和一个TextBlock.如何正确使用BoolToVisibilityConverter切换TextBlock的可见性,并为用户的利益保存此设置?

目前我的情况如下,虽然我收到了一些错误.重要提示,我需要使用ApplicationBar菜单项作为单击事件来驱动TextBox可见性的切换.

编辑

尽管TextBlock的可见性未发生变化,但不再出现错误.

XAML

xmlns:common="clr-namespace:TestApp.Common"

<phone:PhoneApplicationPage.Resources>
    <common:BooleanToVisibilityConverter x:Key="BoolToVisConv" />
</phone:PhoneApplicationPage.Resources>

<ListBox Name="ListBoxEffects" SelectionMode="Single" ItemsSource="{Binding}" Margin="{Binding}"
                     toolkit:TiltEffect.IsTiltEnabled="True" SelectionChanged="ListBox_SelectionChanged" 
                         ItemContainerStyle="{StaticResource ListBoxItemStyle1}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel ItemWidth="159" ItemHeight="Auto" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical"  >
                                <Image Source="{Binding Thumbnail}" Width="155" Height="155" />
                                <TextBlock Text="{Binding Name}" Visibility="{Binding IsTextBlockVisible, Converter={StaticResource BoolToVisConv}}"  TextWrapping="Wrap" FontSize="{StaticResource PhoneFontSizeNormal}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
Run Code Online (Sandbox Code Playgroud)

代码背后

private void BuildLocalizedApplicationBar()
    {
        ApplicationBar = new ApplicationBar();

        ApplicationBarMenuItem showFilterNamesMenuItem = new ApplicationBarMenuItem();
        if (Settings.ShowFilterNames.Value)
            showFilterNamesMenuItem.Text = AppResources.EditPage_EffectNames_Hide;
        else
            showFilterNamesMenuItem.Text = AppResources.EditPage_EffectNames_Show;
        showFilterNamesMenuItem.Click …
Run Code Online (Sandbox Code Playgroud)

c# xaml converter windows-phone-7 windows-phone-8

13
推荐指数
3
解决办法
2万
查看次数

在RunTime上即时更改应用程序语言

我目前正在开发一个metro应用程序,用户可以在运行时更改当前语言,并且所有加载的自定义控件都必须更新有关新语言的文本.问题是,当我使用以下代码更改语言时,应用程序语言会更改,但只有在重新启动应用程序时才更新文本,因为已缓存的页面和控件已被缓存.

LocalizationManager.UICulture = new System.Globalization.CultureInfo((string)((ComboBoxItem)e.AddedItems[0]).Tag);
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = ((ComboBoxItem)e.AddedItems[0]).Tag as String;
Run Code Online (Sandbox Code Playgroud)

如何在不重新启动应用程序的情况下强制在运行时更新所有自定义控件的文本?

c# windows-runtime windows-8.1

9
推荐指数
1
解决办法
5269
查看次数

读/写音频/视频文件的元数据

我需要一些帮助来读/写音频/ vido文件的元数据信息.我搜索了很多,但没有发现任何有用的东西.Taglib sharp是一个开源库,提供读/写元数据的帮助.使用标签lib我可以编辑一些值但不是全部.

TagLib.File videoFile = TagLib.File.Create("test.mp4");
videoFile.Tag.Title = "Test";
videoFile.Tag.Comment = "Nothing";
Run Code Online (Sandbox Code Playgroud)

但我无法编辑以下属性,如作者网址,生产者等.我如何编辑这些属性?

c# taglib-sharp

7
推荐指数
2
解决办法
2万
查看次数

如何获取Windows服务打开的端口?

我想在C#中获取窗口服务及其端口列表.我可以通过使用获得所有窗口服务,ServiceController但我无法获得这些服务的端口.

c# port windows-services

5
推荐指数
1
解决办法
1988
查看次数

Mutliple复选框,具有相同的名称属性循环

我有一个html表单提交给C#ashx处理程序,我希望将插入/更新数据库

我用PHP和Coldfusion编写了这个,但我无法弄清楚如何在C#中做到这一点

HTML表单

     <form id="copyto">
    <input type="hidden" name="operation" value="update" />
    <label><input type="checkbox" name="children[]" checked="checked" value="001">
Andrew Regan</label>

    <label><input type="checkbox" name="children[]" checked="checked" value="101">
Arthur Regan, III</label>

    <input type="checkbox" name="children[]" checked="checked" value="968">
Tim Reagan
    </form>
Run Code Online (Sandbox Code Playgroud)

C#ASHX处理程序

foreach(string key in context.Request.Params["children"]) 
{
    ListDictionary updateParams = new ListDictionary();
    updateParams.Add("rowid", key);
    string sSql = @"insert into temp select * from children where c.id = :rowid";
    dbi.ExecuteNonQuerySql(sSql, updateParams);

}
Run Code Online (Sandbox Code Playgroud)

通常我会迭代PHP中的$ _POST ['children'],然后执行sql

这究竟是如何翻译的?

编辑

好吧我几乎得到了这个,但是我的迭代器遍历了所有请求集合变量,我希望它只遍历一个特定的命名变量,在本例中是"children"

即localhost/page?operation = update&children = 9&children = 8&children = 17

foreach(string key …
Run Code Online (Sandbox Code Playgroud)

c# forms iteration ashx

1
推荐指数
1
解决办法
3201
查看次数

静态构造函数中的static

我无法理解这部分代码请帮忙.

当我这样做

public class TestClass
{
    static TestClass(int i)
    {
    }

    TestClass()
        : this(1)   // Error
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

它给了我错误

'TestApp.TestClass'不包含带有1个参数的构造函数

但是当我这样做时,它没有显示任何错误.

public class TestClass
{
    TestClass(int i)
    {
    }

    static TestClass()
        : this(1)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

有人请解释一下这种行为吗?

c#

0
推荐指数
1
解决办法
96
查看次数