小编Kez*_*zza的帖子

在解析期间设置命名空间

您好,我目前遇到的问题是解析没有任何命名空间的Xml字符串,并添加到具有命名空间的现有XElement.

我的代码:

XElement elem = root.Element(xs + "methodCall");
if (elem != null)
{
    XElement e = XElement.Parse(this.MethodCallXML);

    elem.Add(e);
}
Run Code Online (Sandbox Code Playgroud)

结果:

<methodCall>
  <methodCall service="activity" method="activityDeleteComment" xmlns="">
    <espSessionState>espSessionState1</espSessionState>
    <traceFlowCode>true</traceFlowCode>
    <params>
      <commentID>http://uri1</commentID>
      <isPermanentDelete>false</isPermanentDelete>
    </params>
  </methodCall>
</methodCall>
Run Code Online (Sandbox Code Playgroud)

我的问题是xmlns =""我无法弄清楚如何使用parse方法创建节点并给它一个默认的命名空间来使用.

有没有办法做到这一点?

c# xml linq-to-xml xml-namespaces xml-parsing

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

为什么ListBox AlternationIndex总是返回0

好吧,我知道还有其他几个类似的问题,但我有一个真正的问题,让AlternationIndex在ListBox或ListView上工作.

我的xaml是这样的:

            <ListBox BorderThickness="0" Name="RecentItemsListBox" HorizontalAlignment="Stretch"
                     ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                     ItemsSource="{Binding Path=RecentFilesList}" AlternationCount="100">
                <ListBox.ItemsPanel>

                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Path=(ItemsControl.AlternationIndex), 
                                    RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource IncCnvrtr}}" 
                                       Foreground="DimGray" FontSize="20" FontWeight="Bold"  
                                       HorizontalAlignment="Left" Margin="5,5,15,5" />
                            <StackPanel VerticalAlignment="Center">
                                <TextBlock Text="{Binding ClassName}" Foreground="Black" />
                                <TextBlock Text="{Binding DisplayName}" Foreground="Black" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
Run Code Online (Sandbox Code Playgroud)

转换器将值递增1.这很好,我调试它以确认发送到转换器的值始终为0.

疯狂的是这只适用于ListBox或ListView

一旦我将其更改为ItemsControl,索引是正确的,但我不想要一个项目控件,我想要一个包含它附带的所有功能的列表框.

如果你知道为什么会发生这种情况,我将非常感谢你的帮助.

谢谢

基兰

wpf listbox alternation

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

Linq ToDictionary 不会将类隐式转换为接口

我有以下代码

public class TestAdaptor
{
    private interface ITargetClass
    {
        Guid Id { get; }

        string Name { get; }
    }

    private class MyTargetClass : ITargetClass
    {
        public Guid Id { get; private set; }

        public string Name { get; private set; }

        public MyTargetClass(MySourceClass source)
        {
        }
    }

    private class MySourceClass
    {
        public Guid Id { get; set; }

        public string Name { get; set; }
    }

    private Dictionary<Guid, IEnumerable<ITargetClass>> ConvertItems(Dictionary<Guid, IEnumerable<MySourceClass>> source)
    {
        return source.ToDictionary(kvp => kvp.Key, kvp => …
Run Code Online (Sandbox Code Playgroud)

c# linq todictionary

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

使用数据触发器为线性画笔设置动画

我试图使用数据触发器在边框上设置线性画笔动画但是遇到了无法使用TargetName的问题

我的代码如下,任何人都可以建议一种解决方法吗?

<Border Grid.Row="2" BorderThickness="10" Height="100" Width="100" >
    <Border.BorderBrush>
        <LinearGradientBrush>
            <GradientStop Color="Yellow" Offset="0.0" />
            <GradientStop x:Name="gradient" Color="Orange"  Offset="0.5" />
            <GradientStop Color="Yellow" Offset="1.0" />
        </LinearGradientBrush>
    </Border.BorderBrush>
    <Border.Resources>
        <Style TargetType="Border">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=testBrdrWin, Path=Pulse}" Value="true">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
                                    Storyboard.TargetName="gradient"
                                    Storyboard.TargetProperty="Offset"
                                    From="0" To="1" Duration="0:0:1"
                                    AutoReverse="True" RepeatBehavior="Forever"
                                    />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=testBrdrWin, Path=Pulse}" Value="true">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation
                                    Storyboard.TargetName="gradient"
                                    Storyboard.TargetProperty="Offset"
                                    To="0.5" Duration="0:0:01"
                                    AutoReverse="False"
                                    />
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Resources>
</Border>
Run Code Online (Sandbox Code Playgroud)

谢谢

wpf animation datatrigger storyboard lineargradientbrush

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