小编Bor*_*ris的帖子

如何使StackPanel或DockPanel拉伸以适应WPF中的容器?

我有一个Grid根容器,定义了两列(只有一行).
第一列具有灵活的宽度,第二列具有300px的固定宽度.
接下来,我ListBox在第二列内部放置了水平和垂直拉伸,即填充整个第二列.
最后,我已经为ListBox一个垂直方向定义了一个项目模板StackPanel,里面有一个DockPanel和几个TextBlocks.

<!-- Data template for ListBox -->
<DataTemplate DataType="{x:Type entities:Track}">
  <StackPanel Orientation="Vertical">
    <DockPanel>
      <TextBlock DockPanel.Dock="Left" Text="Now playing" />
      <TextBlock DockPanel.Dock="Right" Text="Time remaining" />
    </DockPanel>
    <TextBlock Text="{Binding Artist}" />
    <TextBlock Text="{Binding Title}" />
  </StackPanel>
</DataTemplate>

...

<ListBox 
  Grid.Column="1" 
  HorizontalAlignment="Stretch" 
  VerticalAlignment="Stretch" />
Run Code Online (Sandbox Code Playgroud)

我有两个问题:

  1. 如何StackPanel填充整个宽度ListBox?现在,它只需要足够的空间来容纳内部DockPanelTextBlock内部.它不适合ListBox或的宽度ListBoxItem.
  2. 接下来,如何DockPanel填充整个宽度StackPanel,即其父级?现在发生的事情是,即使TextBlocks StackPanel的宽度超过了DockPanel它的宽度,它也不会伸展以匹配它们的宽度. …

wpf

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

WPF:无法设置转换器 - 启动应用程序时出错

我想TextBlock根据绑定值设置可见/折叠模式.它不起作用,当我想调试我的应用程序时,我收到此消息:

设置属性'System.Windows.Data.Binding.Converter'引发了异常.

绑定的值是类型Uri.内心有一个InvalidCastException说:

无法将类型为"System.String"的对象强制转换为"System.Windows.Data.IValueConverter".

这是我的转换器:

public class VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, 
        object parameter, CultureInfo culture)
    {
        if (value is string && string.IsNullOrEmpty(value as string))
        {
            return Visibility.Collapsed;
        }
        else if (value == null)
        {
            return Visibility.Collapsed;
        }
        else
        {
            return Visibility.Visible;
        }
    }

    public object ConvertBack(object value, Type targetType, 
        object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是抛出异常的XAML:

...
<Page.Resources>
    <converters:VisibilityConverter x:Key="visibilityConverter" />
</Page.Resources>
...
<TextBlock …
Run Code Online (Sandbox Code Playgroud)

wpf

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

如何使用Javascript迭代ul列表?

我有以下HTML页面(这里简化了页面,因为它是真实的一个样本):

<html>
<head>
<script type="text/javascript" src="JavaScript/Painting.js"></script>
</head>
<body>
<div id="center-wrapper">
    <div id="side-menu">
        <ul>
            <li><a onclick="Paint()">About</a></li>
            <li><a onclick="Paint()">Contents</a></li>
            <li><a onclick="Paint()">Visual</a></li>
            <li><a onclick="Paint()">CSS</a></li>
            <li><a onclick="Paint()">Javascript</a></li>
        </ul>
    </div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我有Painting.js文件(再次,有点简化):

function Paint()
{

    var e = window.event;

    var sender;
    if (e.target)
    {
        sender = e.target;
    }   
    else
    {
        if (e.srcElement)
        {
            sender = e.srcElement;
        }
    }

    for (element in sender.parentNode.parentNode.getElementsByTagName("a"))
    {
        element.style.color = 'blue';
        element.style.backgroundColor = '#FFFFFF';
    }

    sender.style.color = '#FFFFFF';
    sender.style.backgroundColor = '#000000';

}
Run Code Online (Sandbox Code Playgroud)

基本思路是:

  1. 找到导致该事件的HTML元素.
  2. 上去,直到你到达<ul>元素.
  3. 遍历列表项; …

javascript dom

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

在PHP上传文件时是否可以发送其他参数?

我正在使用以下HTML初始化文件上传:

<form enctype="multipart/form-data" action="PHPScripts/upload.php" method="POST">
    <input type="file" id="browseButton" name="image" onchange="this.form.submit();" />
</form>
Run Code Online (Sandbox Code Playgroud)

Upload.php脚本如下所示:

<?php
$file = $_FILES["image"];
$filepath = $file["name"];
$filetmp = $file["tmp_name"];
$filesize = $file["size"];
$filename = basename($filepath);
$filetype = substr($filename, strrpos($filename, ".") + 1);
...
?>
Run Code Online (Sandbox Code Playgroud)

我需要再传递一个参数到我的PHP脚本,但我不知道如何.HTTP方法是POST(可以在上面的代码中看到),但是我应该在哪里放置参数?这甚至可能吗?谢谢你向我澄清这一点.

html php file-upload html-post

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

内联块元素是否可以自动填充可用宽度?

我有一个<div id="content">包含<div id="sub-navigation><div id="main container">,它们是内联块.我希望能够main container填充剩余的可用页面宽度.那可能吗?

Palge布局

我需要columns-strip根据column元素的数量和宽度进行扩展或缩小.如果宽度columns-strip超过宽度,main container则应出现水平滚动条.

CSS:

* {
  margin: 0px;
  padding: 0px;
  font-size: 10pt;
  white-space: normal; 
}

#wrapper {
  margin: 0px 20px; 
  background-color: red;
}

#header {
  margin: 25px 10px 10px 10px;
  height: 50px; 
  background-color: purple;
  color: white;
}

#content {
  margin: 10px; 
  padding: 10px; 
  font-size: 0pt; 
  white-space: nowrap; 
  overflow: hidden; 
  background-color: white;
}

#sub-navigation {
  width: 200px; 
  height: 150px; 
  display: …
Run Code Online (Sandbox Code Playgroud)

html css layout page-layout

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

WPF中的下划线标签,使用样式

我有以下风格:

<Style x:Key="ActionLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="Margin" Value="10,3" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True" />
                <Condition Property="IsEnabled" Value="True" />
            </MultiTrigger.Conditions>
            <Setter Property="Background" Value="Red" />
            <Setter Property="TextBlock.TextDecorations" Value="Underline" />
        </MultiTrigger>
    </Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)

所以基本上,我希望有一个标签,当它被启用并且鼠标光标在它上面时加下划线.这种风格不起作用的部分是<Setter Property="TextBlock.TextDecorations" Value="Underline" />.现在,我在这里做错了什么?谢谢你的帮助.

wpf xaml label styles

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

选择上传文件时自动提交表单

我有一个带有以下输入标记的HTML页面:

...
<input type="file" id="browseContactImageButton" />
... 
Run Code Online (Sandbox Code Playgroud)

单击页面上的按钮将导致打开文件对话框.如果我想进行实际上传,我需要另一个按钮来单击(提交),因为此输入文件按钮仅用于提供文件的路径.

是否可以单击浏览按钮,选择文件并在选择文件后立即启动上传功能?如果是,是否有人可以提供代码段?谢谢.

html javascript ajax file-upload

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

jQuery datepicker不适用于AJAX添加的html元素

我有一个jQuery datepicker函数绑定到"birthday"输入html元素,写在页眉中:

<script type="text/javascript">
    $(function() {
        $( "#birthday" ).datepicker();
    });
</script>
Run Code Online (Sandbox Code Playgroud)

接下来,我有一些AJAX功能 - 它向页面添加了新的输入html元素.那个元素是:

<input type="text" id="birthday" value="" class="detail-textbox1" />
Run Code Online (Sandbox Code Playgroud)

单击该生日元素不会弹出文本字段下方的日期选择器.我期望这样,因为在页面加载后添加了元素,因此它与标题中提供的功能无关.

我怎样才能使它工作?我尝试将脚本从标题移动到正文,但似乎没有任何效果.谢谢.

PS如果我在页面正文中创建id ="birthday"的输入html元素,则everythig按预期工作.似乎只有通过AJAX添加的元素功能失调.

html ajax jquery

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

WPF:样式和/或数据模板(MVVM)中的绑定命令?

这是我的情况的非常快速和简化的解释.我已经为Hyperlink控件定义了一个样式,它们具有Command绑定到ViewModel类(简化)中定义的命令的属性:

<Window.Resources>
  ...
  <Style x:Key="hyperlinkStyle" TargetType="Hyperlink">
    ...
    <Setter Property="Command" Value="{Binding Path=OpenHyperlinkCommand}" />
    ...
  </Style>
  ...
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

接下来,我在我正在设计的窗口中创建了一个内容控件.它有一个定义的数据模板,写在窗口资源中.在该数据模板中,我添加了一些超链接,并设置了这些超链接以使用先前定义的样式.

窗口看起来像这样(简化):

<Window>
  ...
  <ContentControl 
      ...
      ContentTemplate="{StaticResource myDataTemplate}" />
  ...
</Window>
Run Code Online (Sandbox Code Playgroud)

数据模板看起来像这样(简化):

<Window.Resources>
  ...
  <DataTemplate x:Key="myDataTemplate DataType="{x:Type my:MyType}">
    ...
    <TextBlock>
      <Hyperlink 
          Style="{StaticResource hyperlinkStyle}" 
          CommandParameter="{Binding Path=Uri1}">
        <TextBlock Text="{Binding Path=Uri1}" />
      </Hyperlink>
    </TextBlock>
    ...
    <TextBlock>
      <Hyperlink 
          Style="{StaticResource hyperlinkStyle}" 
          CommandParameter="{Binding Path=Uri2}">
        <TextBlock Text="{Binding Path=Uri2}" />
      </Hyperlink>
    </TextBlock>
    ...
  </DataTemplate>
  ...
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

OpenHyperlinkCommand对样式中的绑定不起作用,因为ViewModel绑定到它的窗口包含此命令,但DataTemplate绑定到MyType不包含此命令的对象(也不应该).

我应该如何使这个绑定工作?两个问题:

  1. 这是我的建议:我命名了我的窗口 …

wpf binding styles mvvm

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

WPF:如何在触发器属性属性中引用其他控件?

我有一个WPF页面.页面有一些内容,但页面根布局的最后一个子组件是我创建的用户控件.它看起来像这样:

<UserControl DataContext=UserControlViewModel>
  <UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="visibilityConverter" />
  </UserControl.Resources>
  <Grid 
      Name="grid" 
      Visibility="{Binding IsOn, Converter={StaticResource visibilityConverter}}">
    <!-- Border to dim everything behind my user control -->
    <Border Background="#000000" Opacity="0.4" />
    <!-- The following border is red and holds the content -->
    <Border 
        Width="{Binding ElementName=txt, Path=ActualWidth}" 
        Height="{Binding ElementName=txt, Path=ActualHeight}" 
        Margin="{Binding ElementName=txt, Path=Margin}" 
        HorizontalAlignment="{Binding ElementName=txt, Path=HorizontalAlignment}" 
        VerticalAlignment="{Binding ElementName=txt, Path=VerticalAlignment}" 
        Background="Red">
      <TextBlock 
          Name="txt"
          Width="200" 
          Height="100" 
          Margin="20" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center" 
          Text="This is my super awesome message!" />
    </Border>
  </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

默认情况下,对象的IsOn属性UserControlViewModel设置为false,即用户控件不可见.我已经实现了一些将此属性更改为的逻辑, …

wpf xaml styles

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

标签 统计

wpf ×5

html ×4

styles ×3

ajax ×2

file-upload ×2

javascript ×2

xaml ×2

binding ×1

css ×1

dom ×1

html-post ×1

jquery ×1

label ×1

layout ×1

mvvm ×1

page-layout ×1

php ×1