小编Jas*_*son的帖子

Windows 10 UWP中的可视状态管理器未在页面加载时应用初始状态

我有一个页面,其中包含一个相对面板,可根据宽度重新组织.但是,除非宽度> 720px,否则它似乎不会在加载时应用任何状态.如果我在加载后调整页面大小,则两个状态都有效.

解决方法是检查加载页面上的窗口大小并手动选择状态,但我相信这应该自动处理?我有其他页面可以工作,我不确定我在做什么不同.这是我的代码的简化版本,我有它设置红色/蓝色背景,所以我可以判断是否/正在应用哪个状态

<Page.Resources>
    <converters:HighlightConverter x:Key="HighlightConverter"/>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <gui:MainAppBar x:Name="mainAppBar" Grid.Row="0"/>

    <ScrollViewer Grid.Row="1">
        <RelativePanel>

            <StackPanel x:Name="ZonesContainer" Margin="12,12,0,0">
                <TextBlock Text="Zones"/>
                <ItemsControl x:Name="ZonesPanel">
                    <ItemsControl.ItemContainerStyle>
                        <Style TargetType="ContentPresenter">
                            <Setter Property="Margin" Value="6"/>
                        </Style>
                    </ItemsControl.ItemContainerStyle>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <ItemsWrapGrid x:Name="ZonesWrapGrid" Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel x:Name="Panel" Orientation="Horizontal">
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>

            <StackPanel x:Name="SourcesContainer" RelativePanel.RightOf="ZonesContainer" Margin="12,12,0,0">
                <GridView x:Name="SourcesPanel" Header="Sources">
                </GridView>
            </StackPanel>

            <StackPanel x:Name="NetworkServicesContainer" RelativePanel.Below="SourcesContainer" RelativePanel.AlignLeftWith="SourcesContainer" Margin="12,12,0,0">
                <GridView x:Name="NetworkServicesPanel" Header="Network">
                </GridView>
            </StackPanel>

        </RelativePanel>
    </ScrollViewer>

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="WindowStates">
            <VisualState x:Name="WideState"> …
Run Code Online (Sandbox Code Playgroud)

c# xaml win-universal-app uwp

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

添加新的XElement会在保存时将整个XML文件附加到现有文件

我创建了一个新的xml文档(如果找不到),然后打开它以创建一个新条目.但是,它似乎只是将一个已完成的新XML文件附加到我创建的空白文件的末尾

创作后:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Devices />
Run Code Online (Sandbox Code Playgroud)

添加新的xelement后:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Devices /><?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Devices>
  <device>
    <name>blah</name>
    <src00>True</src00>
  </device>
</Devices>
Run Code Online (Sandbox Code Playgroud)

我的代码...我尝试添加两种不同的方式,两者都有相同的结果

           // Create file if not found
            if (!storage.FileExists("settings\\mydevices.xml"))
            {
                using (IsolatedStorageFileStream stream = storage.OpenFile("settings\\mydevices.xml", FileMode.Create, FileAccess.ReadWrite))
                {
                    XDocument devicesDoc =
                        new XDocument(
                            new XDeclaration("1.0", "utf-8", "yes"),
                            new XElement("Devices")
                            );

                    System.IO.StreamWriter file = new System.IO.StreamWriter(stream);
                    devicesDoc.Save(file);
                    file.Dispose();
                }
            }


            // Add new device
            using (IsolatedStorageFileStream stream = storage.OpenFile("settings\\mydevices.xml", FileMode.Open, FileAccess.ReadWrite))
            {

                XDocument mydevicesXml = XDocument.Load(stream);
                //XElement …
Run Code Online (Sandbox Code Playgroud)

.net c# xml linq-to-xml windows-phone-7

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

用标签拆分字符串,保留分隔符

我需要一些帮助编写正则表达式语句来拆分包含一些标签的字符串(不是真正的HTML,我只是使用使用<i><b>标签格式化一些文本),并保留分隔符.例如这个字符串:

<b>a bold quote:</b> this is some sample test. How <i>do</i> I do this?
Run Code Online (Sandbox Code Playgroud)

将转变为:

<b>a bold quote:</b>
 this is sample text. How 
<i>do</i>
 I do this?
Run Code Online (Sandbox Code Playgroud)

c# regex

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

标签 统计

c# ×3

.net ×1

linq-to-xml ×1

regex ×1

uwp ×1

win-universal-app ×1

windows-phone-7 ×1

xaml ×1

xml ×1