相关疑难解决方法(0)

WPF数据绑定:如何访问"父"数据上下文?

我有一个窗口中包含的列表(见下文).窗口DataContext有两个属性,ItemsAllowItemCommand.

如何获取针对窗口的属性需要解析HyperlinkCommand属性DataContext

<ListView ItemsSource="{Binding Items}">
  <ListView.View>
    <GridView>
      <GridViewColumn Header="Action">
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <StackPanel>
              <TextBlock>

                <!-- this binding is not working -->
                <Hyperlink Command="{Binding AllowItemCommand}"
                           CommandParameter="{Binding .}">
                    <TextBlock Text="Allow" />
                </Hyperlink>

              </TextBlock>
            </StackPanel>
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView>
  </ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)

data-binding wpf datacontext

202
推荐指数
3
解决办法
16万
查看次数

XAML:绑定DataTemplate中的属性

我对XAML很新,但很乐意学习它.我真正挣扎的是将属性绑定到一个元素DataTemplate.

我创建了一个简单的WPF示例,(希望)解释了我的问题.

我这个例子我试图将a的Visibility属性绑定到我的viewmodel CheckBox中的DataTemplate一个Property.(纯粹用于学习/演示,使用此场景.)

我有一个简单的DataModel命名Item,但在这个例子中没什么关系.

class Item : INotifyPropertyChanged
{

    // Fields...
    private bool _IsRequired;
    private string _ItemName;
Run Code Online (Sandbox Code Playgroud)

还有一个名为ItemViewModel的相当简单的View Model.

class ItemViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Item> _Items;
    private bool _IsCheckBoxChecked;
    private bool _IsCheckBoxVisible;

    public ObservableCollection<Item> Items
    {
        get { return _Items; }
        set { _Items = value; }
    }


    public bool IsCheckBoxChecked
    {
        get { return _IsCheckBoxChecked; }
        set
        {
            if (_IsCheckBoxChecked == value)
                return;
            _IsCheckBoxChecked = value;
            if (PropertyChanged …
Run Code Online (Sandbox Code Playgroud)

xaml binding properties datatemplate

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

WPF - 具有多重绑定的工具提示

我想在文本块中创建一个带有多绑定的工具提示,但无论我尝试它都不起作用.

这是我到目前为止所尝试的:

<TextBlock Text="{Binding Description, StringFormat='Description : {0}{}'}">
    <ToolTipService.ToolTip>
        <TextBlock>
            <TextBlock.Text>
                <MultiBinding StringFormat="Description : {0}{1}{}">
                    <Binding Path="FirstDescription" />
                    <Binding Path="SecondDescription" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </ToolTipService.ToolTip>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试它时,我在工具提示上看到的是:System.Windows.Controls.TextBlock.

当我尝试没有tooltipservice,只有工具提示,像这样:

<TextBlock Text="{Binding Description, StringFormat='Description : {0}{}'}">
    <ToolTip>
        <TextBlock>
            <TextBlock.Text>
                <MultiBinding StringFormat="Description : {0}{1}{}">
                    <Binding Path="FirstDescription" />
                    <Binding Path="SecondDescription" />
                </MultiBinding>
            </TextBlock.Text>
        </TextBlock>
    </ToolTip>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

屏幕刚刚卡住了.

c# wpf tooltip multibinding

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

GestureRecognizers 在 ListView 中不起作用

我有一个 ListView 如下

<ListView
        Grid.Row="0"
        Margin="0"
        x:Name="ItemsListView"
        ItemsSource="{Binding SourceItems}"
        VerticalOptions="FillAndExpand"
        HasUnevenRows="false"
        RefreshCommand="{Binding LoadItemsCommand}"
        IsPullToRefreshEnabled="true"
        IsRefreshing="{Binding IsBusy}"
        ItemSelected="OnItemSelected"
        IsVisible="{Binding ShowListView}"
        RowHeight="55">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid
                        Margin="15,0,0,0"
                        Padding="0"
                        RowSpacing="0"
                        ColumnSpacing="0">
                        <Grid.RowDefinitions>
                            <RowDefinition
                                Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition
                                Width="1*" />
                            <ColumnDefinition
                                Width="7*" />
                            <ColumnDefinition
                                Width="1*" />
                            <ColumnDefinition
                                Width="1*" />
                        </Grid.ColumnDefinitions>
                        <Image
                            VerticalOptions="CenterAndExpand"
                            HorizontalOptions="CenterAndExpand"
                            HeightRequest="35"
                            WidthRequest="35"
                            Grid.Row="0"
                            Grid.Column="0"
                            Aspect="AspectFit"
                            Source="{Binding Icon}">
                        </Image>
                        <StackLayout
                            VerticalOptions="CenterAndExpand"
                            Spacing="0"
                            CompressedLayout.IsHeadless="true"
                            Margin="15,0,0,0"
                            Grid.Row="0"
                            Grid.Column="1">
                            <Label
                                VerticalTextAlignment="Start"
                                Text="{Binding Name}"
                                FontAttributes="Bold"
                                LineBreakMode="NoWrap"
                                Style="{DynamicResource ListItemTextStyle}"
                                FontSize="16" />
                            <Label
                                VerticalTextAlignment="Start"
                                Text="{Binding Description}"
                                LineBreakMode="NoWrap" …
Run Code Online (Sandbox Code Playgroud)

c# xaml xamarin xamarin.forms

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