小编Chr*_* W.的帖子

ContentControl 中嵌入的交互触发器

因此,为了使问题简单,我需要使用类似的东西数十次;

    <Rectangle>
        <i:Interaction.Triggers>
             <i:EventTrigger EventName="MouseLeftButtonDown">
                  <ei:ChangePropertyAction TargetName="AnotherObjectOnTheView"
                                           PropertyName="Visibility"
                                           Value="Visible" />                           
             </i:EventTrigger>                        
        </i:Interaction.Triggers>
   </Rectangle>
Run Code Online (Sandbox Code Playgroud)

但显然我不想在我需要的地方粘贴几十次。所以我尝试将它们放入ContentControl类似这样的东西中:

<Style x:Key="MyThingy" TargetType="ContentControl">
        <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ContentControl">
                <Rectangle>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseLeftButtonDown">
                            <ei:ChangePropertyAction TargetName="AnotherObjectOnTheView"
                                                     PropertyName="Visibility"
                                                     Value="Visible" />                                         
                        </i:EventTrigger>                        
                    </i:Interaction.Triggers>
                </Rectangle>                    
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

有了这个想法,我可以通过调用模板来替换每个实例的所有内容;

<ContentControl Style="{StaticResource MyThingy}"/>
Run Code Online (Sandbox Code Playgroud)

除了问题是,当嵌入ContentControl,交互触发器似乎不会触发。它会很好地显示模板化项目,但似乎忽略了触发器?

所以问题是,为什么附加到模板化项目的触发器被忽略,或者是否有更好的方法来完成我想要的事情?

silverlight wpf xaml styles contentcontrol

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

C# WPF 出现错误 - System.InvalidOperationException:

我刚刚开始学习使用 C# WPF 进行 Windows 应用程序开发,并且我们已经获得了自学项目来开发一个 Windows 应用程序。我正在尝试创建客户端与客户端聊天的应用程序。我创建了一个类 MainWindow.xaml 和 MainWindow.xaml.cs 来处理这个问题。当我从主窗体调用该类时,出现以下错误。

在此输入图像描述

这是两个类:

<Window x:Class="Chat_Client.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Chat_Client"
    mc:Ignorable="d"
    Title="Chat: Client-to-Client" Height="450" Width="625">
<Grid>
    <Label x:Name="label" Content="IP" HorizontalAlignment="Left"   Margin="39,52,0,0" VerticalAlignment="Top"/>
    <Label x:Name="label1" Content="Port" HorizontalAlignment="Left" Margin="39,100,0,0" VerticalAlignment="Top"/>
    <Label x:Name="label2" Content="IP" HorizontalAlignment="Left" Margin="287,59,0,0" VerticalAlignment="Top"/>
    <Label x:Name="label3" Content="Port" HorizontalAlignment="Left" Margin="287,100,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.037,-0.343"/>
    <TextBox x:Name="textLocalIp" HorizontalAlignment="Left" Height="23" Margin="98,59,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
    <TextBox x:Name="textLocalPort" HorizontalAlignment="Left" Height="23" Margin="98,104,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
    <TextBox x:Name="textFriendsIp" HorizontalAlignment="Left" Height="23" Margin="342,59,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="textBox2_TextChanged"/>
    <TextBox x:Name="textFriendsPort" HorizontalAlignment="Left" Height="23" …
Run Code Online (Sandbox Code Playgroud)

.net c# windows wpf xaml

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

带MouseOver的Collection ItemTemplate资源中的动态PAth图标按钮

我正在使用icons.XAML图像,将它们插入文本块上方的按钮中。在将鼠标悬停在图像本身之前,一切看起来都很不错。灰色框仅出现在图片上方:

在此处输入图片说明

如何摆脱灰色框?

这是图标之一:

<Canvas x:Key="appbar_cog" Width="38" Height="46" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0" Background="Transparent">
    <Path Width="37.6263" Height="37.6262" Canvas.Left="15" Canvas.Top="5" Stretch="Fill" Fill="#FF5DBEBE" Data="F1 M 27.5314,21.8628L 33.0126,19.4224L 34.7616,23.3507C 36.6693,22.9269 38.6044,22.8903 40.4668,23.2026L 42.0083,19.1868L 47.6098,21.337L 46.0683,25.3528C 47.6612,26.3669 49.0747,27.6889 50.2088,29.2803L 54.1371,27.5313L 56.5776,33.0126L 52.6493,34.7616C 53.0731,36.6693 53.1097,38.6043 52.7974,40.4668L 56.8131,42.0083L 54.6629,47.6097L 50.6472,46.0683C 49.6331,47.6613 48.3111,49.0748 46.7197,50.2089L 48.4686,54.1372L 42.9874,56.5776L 41.2384,52.6493C 39.3307,53.0731 37.3957,53.1097 35.5333,52.7974L 33.9918,56.8131L 28.3903,54.6629L 29.9318,50.6472C 28.3388,49.6331 26.9252,48.3111 25.7911,46.7196L 21.8628,48.4686L 19.4224,42.9873L 23.3507,41.2383C 22.9269,39.3307 22.8903,37.3957 23.2026,35.5332L 19.1869,33.9918L 21.3371,28.3903L 25.3528,29.9318C 26.3669,28.3388 27.6889,26.9252 29.2804,25.7911L 27.5314,21.8628 Z M 34.3394,29.7781C 29.7985,31.7998 27.7564,37.1198 29.7781,41.6606C 31.7998,46.2015 …
Run Code Online (Sandbox Code Playgroud)

wpf xaml app.xaml visual-studio-2015

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

列表框项目之间的垂直间隙(删除?)

我的列表框是从使用 DataTemplate 进行数据绑定的对象列表驱动的数据,例如:

            <ListBox x:Name="TheMainListBox" 
                 ScrollViewer.IsVerticalRailEnabled="True" 
                 ScrollViewer.IsHorizontalRailEnabled="False" 
                 HorizontalAlignment="Left" 
                 VerticalAlignment="Top"
                 Height="540" 
                 ItemsSource="{Binding}"
                 Width="Auto"
                 Margin="0"
                 Padding="0"
                 Background="Yellow"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                 ScrollViewer.VerticalScrollBarVisibility="Auto" 
                 SelectionChanged="TheMainListBox_SelectionChanged" 
                 DoubleTapped="TheMainListBox_DoubleTapped"  
                 >
Run Code Online (Sandbox Code Playgroud)

模板:

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid or Stackpanel Background="Blue"
                         Padding="0"                                    
                         BorderBrush="Black"
                         BorderThickness="1"
                         Margin="0"
                     >
                     .... Binding Textboxes/blocks
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

我最终得到一个黄色容器,即列表框,..里面有蓝色矩形,即列表框项目,但它们之间有一个垂直间隙。我可以设置负的垂直顶部边距,但这很粗糙,并且不适用于顶部项目。如何将项目之间的垂直间隙减小到零。

如果创建一个包含静态项的 ListBox,每个项都位于 ListBoxItem 容器中,例如:

                <ListBoxItem BorderThickness="1" Width="100" Height="50"
                  BorderBrush="Black" Background="Red"/>
Run Code Online (Sandbox Code Playgroud)

一切都按要求进行。

那么如何使用 ItemTemplate/DataBinding 消除项目之间的垂直间距呢? 这是关键任务,请提前致谢。

c# xaml listbox win-universal-app

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

CLI CORS代理不改变原点,仍然获得403 reqs?

是的,我发现了很多相似的东西,但我的实例仍未解决.我想避免杀死浏览器端的安全性,而是让代理完成它的工作,但我担心我在设置中遗漏了一些无聊的细节,我无论如何都不是CORS专家.

所以,我得到的...... 403;

Failed to load http://localhost:10000/some/rest/endpoint: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

其中localhost:10000是我的api url,:4200是默认的Angular CLI实例.

所以我配置了一个代理,因为我希望在angular.json中这样做;

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular-proj:build",
            "proxyConfig": "./proxy.conf.json"
          },
Run Code Online (Sandbox Code Playgroud)

并添加proxy.conf.json;

{
    "/some/rest/*": {
      "target": "http://localhost:10000",
      "secure": false,
      "changeOrigin": true,
      "logLevel": "debug"
    }
  }
Run Code Online (Sandbox Code Playgroud)

我提供它甚至标记CLI服务确认的proxy.conf;

[HPM] Proxy created: /some/rest -> http://localhost:10000 等等...

....除了我仍然得到403,仍然在Request*标题中看到;

Host: localhost:10000
Origin: http://localhost:4200
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,我在这里错过了什么内容?我不想把所有来源的请求写成星号,而且我不想关闭浏览器检查,我更愿意将这个很好地捆绑在服务配置中,就像我这样做另外一对眼睛非常受欢迎.干杯

ADDENDUM …

cors angular-cli angular

5
推荐指数
2
解决办法
586
查看次数

更新显示的数字以匹配其在纯 javascript 中元素顺序的位置

我有代码允许我拖放以重新排列项目并将它们从一个容器移动到另一个容器,但我也想更新 span 标签内的数字以匹配它的位置。

例如,“科罗拉多”在 0 位置,但是当我将它拖到“犹他州”之后时,我想更新“蒙大拿州”以使其旁边有“0”,“犹他州”为“1”,“科罗拉多州”为“2”,但我不知道该怎么做。

这是 JS 小提琴:https : //jsfiddle.net/benschnell/0wbfoqk9/

const draggables = document.querySelectorAll('.draggable')
const containers = document.querySelectorAll('.container')

draggables.forEach(draggable => {
  draggable.addEventListener('dragstart', () => {
    draggable.classList.add('dragging')
  })

  draggable.addEventListener('dragend', () => {
    draggable.classList.remove('dragging')
  })
})

containers.forEach(container => {
  container.addEventListener('dragover', dragOver);
})

function dragOver(e) {
   e.preventDefault()
    const afterElement = getDragAfterElement(this, e.clientY)
    const draggable = document.querySelector('.dragging')
    if (afterElement == null) {
      this.appendChild(draggable)
    } else {
      this.insertBefore(draggable, afterElement)
    }
}

function getDragAfterElement(container, y) {
  const draggableElements = [...container.querySelectorAll('.draggable:not(.dragging)')]

  return draggableElements.reduce((closest, child) => …
Run Code Online (Sandbox Code Playgroud)

javascript

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

在飞溅屏幕Windows Phone 7芒果上的邋Gra的渐变

想知道是否有人知道如何在闪屏中保持良好的平滑渐变?我已经尝试了.jpg并加载了直接的xaml作为徽标控件资源,并且我已经嵌入了一个视图框中.在模拟器中它看起来很棒!虽然在手机上它仍然具有那种波涛汹涌的外观,但它并没有让我看起来很酷的标志正义作为一个漂亮的闪屏.有任何想法吗?

c# xaml expression-blend windows-phone-7

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

删除ListViewItem周围的空格填充边距

想为按钮添加样式,并且不明白为什么我必须包括以下代码行,而我不想在按钮上添加任何边框:

<Border Background="{TemplateBinding Background}">
Run Code Online (Sandbox Code Playgroud)

完整的代码:

<Style x:Key="ButtonStyleRed" TargetType="{x:Type Button}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border Background="{TemplateBinding Background}">
                    <StackPanel Orientation="Horizontal" Width="200">
                        <Rectangle Width="4" Height="30" Fill="#64dd17" Margin="0,0,10,1" RadiusX="2" RadiusY="2"/>
                        <TextBlock Text="{Binding Path=DataContext.FlowStageName,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Button}}}" 
                                   VerticalAlignment="Center" FontSize="14" Foreground="White" TextWrapping="WrapWithOverflow"/>
                    </StackPanel>
                 </Border>
                 <ControlTemplate.Triggers>
                    <Trigger Property="IsFocused" Value="True"/>
                    <Trigger Property="IsDefaulted" Value="True"/>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="#263238"></Setter>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True"/>
                    <Trigger Property="IsEnabled" Value="False"/>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="Margin" Value="0"/>
    <Setter Property="Padding" Value="0"></Setter>
    <Setter Property="Width" Value="200"/>
    <Setter Property="Height" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml

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

是否可以在元素之间对齐渐变?

我试图在日历中为过去的日子添加渐变,但渐变线未对齐看起来有点无聊。

div.month {
  flex: 1 1 auto;
  display: grid;
  grid-gap: 1px;
  grid-template-columns: repeat(7, 1fr);
  background-color: var(--color-border);

}

div.day {
  background-color: var(--color-fill);
}

div.day + .past {
  background: repeating-linear-gradient(
    -45deg,
    var(--color-fill),
    var(--color-fill) 1.5rem,
    var(--color-gradient-calendar-past) 1.5rem,
    var(--color-gradient-calendar-past) 3rem
  );
}
Run Code Online (Sandbox Code Playgroud)
<div class="month noselect">
        <div class="day void"><div class="day-number"></div></div>
        <div class="day past"><div class="day-number">1</div></div>
        <div class="day past"><div class="day-number">2</div></div>
        <div class="day past"><div class="day-number">3</div></div>
        <div class="day past"><div class="day-number">4</div></div>
        ...
        <div class="day today"><div class="day-number">17</div></div>
Run Code Online (Sandbox Code Playgroud)

如果不将日子变成正方形(aspect-ratio: 1/1),是否可以对齐这些梯度?

在此输入图像描述

我在想也许我可以让整个组件的背景变成渐变,但是如果我想在其他日子使用不同颜色的相同渐变,我就会遇到同样的问题。

在此输入图像描述

css gradient

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

解释如何将VisualStateManager用于初学者

我知道很少Xaml/WPF.我正在尝试Style在Windows 8 metro应用程序中设计一个Button具有洋红色背景的自定义,并且在按下时,具有蓝色背景.我知道我需要使用VisualStateManager但我找不到任何在线对任何人有意义的东西对这个问题知之甚少.有很多假设的知识.这是我到目前为止所得到的:

<Style x:Name="test" TargetType="Button">
        <Setter Property="Background" Value="Magenta"/>
        <Setter Property="Content" Value="Test style" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid>                          
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <turn the background blue>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
Run Code Online (Sandbox Code Playgroud)

这段代码可能是非常错误的,但正如我所说,我一直试图修补一些我不理解的信息以创造结果.

感谢您的时间

wpf xaml microsoft-metro windows-8

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