标签: binding

来自ToolTip或ContextMenu的RelativeSource绑定

我在这做错了什么?:

 <GridViewColumn>
    <GridViewColumn.CellTemplate>
       <DataTemplate>
          <Button>
            <Button.ToolTip>
              <TextBlock Text="{Binding Path=Title, RelativeSource={RelativeSource AncestorType=Window}}" />
Run Code Online (Sandbox Code Playgroud)

这只是一个简单的例子,无论如何都不起作用:)实际上我需要从Window的DataContext范围内的另一个属性中获取一个值.

帮帮我吧

wpf xaml binding relativesource

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

如何敲除绑定到backgroundImage URL?

我有一个可观察的数组

var items= [
    {"image": "/images/image1.jpg" },
    {"image": "/images/image2.jpg" },
    {"image": "/images/image3.jpg" }
];
Run Code Online (Sandbox Code Playgroud)

我的模板看起来像这样:

<div data-bind="foreach: items">
   <div class="box" data-bind="style: {'background-image': url(image)}"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用.我想要的是这个:

<div>
  <div class="box" style="background-image: url(/images/image1.jpg)"></div>
  <div class="box" style="background-image: url(/images/image2.jpg)"></div>
  <div class="box" style="background-image: url(/images/image3.jpg)"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

我怎么能达到这个目的?

css binding knockout.js

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

如何通过活动中的绑定从抽屉页眉布局中获取视图?

所以这是我的activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        tools:context="MainActivity"
    >
    <!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <!-- As the main content view, the view below consumes the entire
             space available using match_parent in both dimensions. -->

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/ll_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/my_awesome_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@android:color/black"
                    android:fitsSystemWindows="true"
                    >

                    <TextView
                        android:id="@+id/toolbar_title"
                        android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

binding android view drawer android-activity

30
推荐指数
6
解决办法
3万
查看次数

在WPF中使用DataContext作为CommandParameter

我想将当前的DataContext(它是ViewModel的一个实例)作为WPF Button上的CommandParameter传递.我应该使用什么语法?

<Button 
  x:Name="btnMain"
  Command="infra:ApplicationCommands.MyCommand"
  CommandParameter="{Binding ???}"
 />
Run Code Online (Sandbox Code Playgroud)

wpf datacontext xaml binding

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

使用MVVM绑定ComboBox SelectedItem

我的ComboBox中SelectedItem有问题.

<ComboBox Name="cbxSalesPeriods"
        ItemsSource="{Binding SalesPeriods}"
        DisplayMemberPath="displayPeriod"
        SelectedItem="{Binding SelectedSalesPeriod}"
        SelectedValuePath="displayPeriod"
        IsSynchronizedWithCurrentItem="True"/>
Run Code Online (Sandbox Code Playgroud)

这没什么好的 如果我打开ComboBox,我会看到值.

在此输入图像描述 如果我选择一个项目,则不会显示所选项目.

有人有想法吗?

在我的ViewModel中,我有以下两个属性:

public ObservableCollection<SalesPeriodVM> SalesPeriods { get; private set; }

private SalesPeriodVM selectedSalesPeriod;
public SalesPeriodVM SelectedSalesPeriod
{
    get { return selectedSalesPeriod; }

    set 
    {
        if (selectedSalesPeriod != value)
        {
            selectedSalesPeriod = value;
            RaisePropertyChanged("SelectedSalesPeriod");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这些是该类的一些属性:

public SalesPeriodVO Vo
{
    get { return period; }
}

public int Year
{
    get { return period.Year; }
    set
    {
        if (period.Year != value)
        {
            period.Year …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf binding mvvm

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

如何在 SwiftUI 中分配可选的 Binding 参数?

我正在尝试NavBar使用一些可选的构建自定义Views,例如搜索栏(但仅当视图需要显示它时)。

基本上,我需要在视图中传递一些@State属性@Binding。但我也需要它们作为Optional参数。

下面是一个例子:

struct NavBar: View {
    
    var isSearchable: Bool?
    
    @Binding var searchTxt: String
    @Binding var searchIsOn: Bool
    
    var navBarTitle: String
    var navBarAction: (() -> Void)?
    var navBarImage: String?
    
    init(navBarTitle: String, navBarAction: (() -> Void)? = nil, navBarImage: String? = nil, isSearchable: Bool? = false, searchTxt: (Binding<String>)?, searchIsOn : (Binding<Bool>)?) {
        self.navBarTitle = navBarTitle
        if(navBarAction != nil) {
            self.navBarAction = navBarAction!
        }
        if(navBarImage != nil) {
            self.navBarImage = navBarImage!
        } …
Run Code Online (Sandbox Code Playgroud)

binding swift swiftui

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

如何隐藏绑定到无法执行的命令的按钮?

我没有禁用自动发生的按钮,而是隐藏(或者更确切地说是折叠了按钮的可见性).

wpf binding

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

wpf控制宽度绑定

我有两个内容边框,第二个边框宽度根据内容而变化,我正在尝试将第一个边框绑定到第二个边框宽度,但它不起作用,我不确定我缺少什么.有人可以给我一些方向吗?以下是我目前正在尝试的一个例子.

<Border x:Name="border1" Width="{Binding Path=Width, ElementName=border2}">
    ... 
</Border>

<Border x:Name="border2">
    ...
</Border>
Run Code Online (Sandbox Code Playgroud)

wpf binding width

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

包装器,绑定和端口有什么区别?

在软件可移植性环境中,这三个概念有什么区别?

所以例如,我想使用ncurses库,原始的ncurses库是用C语言编写的,但我的应用程序是用C++编写的,然后我找到了"ncurses wrapper","绑定到ncurses"和"ncurses port".我应该使用哪一个?

每个人的利弊是什么?

port binding portability wrapper

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

为动态内容绑定ContentControl内容

我目前正在尝试通过使用ListView(作为选项卡)和带有绑定内容属性的ContentControl来实现带有隐藏选项卡的tabcontrol的功能.

我读了一下这个主题,如果我做对了,它应该这样工作:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="20.0*"/>
        <ColumnDefinition Width="80.0*"/>
    </Grid.ColumnDefinitions>
    <ListBox Grid.Column="0">
        <ListBoxItem Content="Appearance"/>
    </ListBox>

    <ContentControl Content="{Binding SettingsPage}" Grid.Column="1"/>
</Grid>
.
.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ContentControl x:Key="AppearancePage">
        <TextBlock Text="Test" />
    </ContentControl>
    <ContentControl x:Key="AdvancedPage">
        <TextBlock Text="Test2" />
    </ContentControl>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

并在代码背后:

public partial class MainWindow : MetroWindow
  {
    private ContentControl SettingsPage;
    private ResourceDictionary SettingsPagesDict = new ResourceDictionary();

    public MainWindow()
    {
        InitializeComponent();

        SettingsPagesDict.Source = new Uri("SettingsPages.xaml", UriKind.RelativeOrAbsolute);
        SettingsPage = SettingsPagesDict["AppearancePage"] as ContentControl;
Run Code Online (Sandbox Code Playgroud)

尽管它没有抛出任何错误,但它不会显示"Test"TextBlock.

我可能有错误的绑定概念,请给我一个正确方向的提示.

问候

c# wpf xaml binding contentcontrol

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