本文的目的是介绍c#–TreeView.ItemContainerGenerator.ContainerFromItem为非根项目返回null.解决方法?的详细情况,我们将通过专业的研究、有关数据的分
本文的目的是介绍c# – TreeView.ItemContainerGenerator.ContainerFromItem为非根项目返回null.解决方法?的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于AbstractMultiTenantConnectionProvider 在 LocalContainerEntityManagerFactoryBean 中配置、android – MenuItemCompat.getActionView返回Null、Angular 2:ngSwitch或ViewContainerRef.createComponent、asp.net listview Container.DataItemIndex的知识。
本文目录一览:- c# – TreeView.ItemContainerGenerator.ContainerFromItem为非根项目返回null.解决方法?
- AbstractMultiTenantConnectionProvider 在 LocalContainerEntityManagerFactoryBean 中配置
- android – MenuItemCompat.getActionView返回Null
- Angular 2:ngSwitch或ViewContainerRef.createComponent
- asp.net listview Container.DataItemIndex
c# – TreeView.ItemContainerGenerator.ContainerFromItem为非根项目返回null.解决方法?
<Window x:xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.Resources> <x:Array xmlns="clr-namespace:System;assembly=mscorlib" x:Key="Array" Type="Object"> <x:ArrayExtension Type="Object"> <String>String</String> </x:ArrayExtension> </x:Array> </Window.Resources> <TreeView ItemsSource="{StaticResource Array}" selecteditemchanged="Handler"> <TreeView.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding}"> <TextBlock Text="Array"/> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}"/> </DataTemplate> </HierarchicalDataTemplate.ItemTemplate> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView>
namespace WpfApplication1 { public partial class Window1 : Window { public Window1() { InitializeComponent(); } private void Handler(object sender,EventArgs e) { var treeView = sender as TreeView; var container = treeView.ItemContainerGenerator.ContainerFromItem(treeView.SelectedItem); Title = container != null ? container.ToString() : "null"; } } }
解决方法
但是,有一种非常简单的方法可以执行您想要执行的操作:注册到TreeViewItem.Selected事件,而不是注册到selecteditemchanged事件,该事件将使用设置为所选TreeViewItem的OriginalSource冒泡.
XAML:
<TreeView ItemsSource="{StaticResource Array}" TreeViewItem.Selected="TreeViewItem_Selected">
代码背后:
private void TreeViewItem_Selected(object sender,RoutedEventArgs e) { TreeViewItem container = (TreeViewItem) e.OriginalSource; Title = container != null ? container.ToString() : "null"; }
AbstractMultiTenantConnectionProvider 在 LocalContainerEntityManagerFactoryBean 中配置
@Credo 你好,想跟你请教个问题:
我也在做多租户系统开发,想问你一下,你有 AbstractMultiTenantConnectionProvider 在 LocalContainerEntityManagerFactoryBean 中配置的例子么?多谢
android – MenuItemCompat.getActionView返回Null
我正在尝试为我的菜单项实现自定义布局并经历了许多解决方案,每当我尝试在为menuItem为actionLayout指定的布局中获取TextView时,我将获得Null指针异常,因为getActionView返回null.
home_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_notifications"
android:title=""
app:showAsAction="always"
android:visible="true"
android:icon="@drawable/ic_notifications_black_24dp"
android:orderInCategory="3"
android:actionLayout="@layout/counter_action_bar_notification_icon"
/>
<!--android:icon="@drawable/ic_notifications_black_24dp"-->
<!--android:actionLayout="@layout/bage_layout"-->
</menu>
counter_action_bar_notification_icon
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center"
android:clickable="true">
<ImageView
android:id="@+id/hotlist_bell"
android:src="@drawable/ic_notifications_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="0dp"
android:contentDescription="bell"
/>
<TextView
android:id="@+id/hotlist_hot"
android:layout_width="wrap_content"
android:minWidth="17sp"
android:textSize="12sp"
android:textColor="#ffffffff"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@null"
android:layout_alignTop="@id/hotlist_bell"
android:layout_alignRight="@id/hotlist_bell"
android:layout_marginRight="0dp"
android:layout_marginTop="3dp"
android:paddingBottom="1dp"
android:paddingRight="4dp"
android:paddingLeft="4dp"
android:background="@drawable/bage_circle"/>
</RelativeLayout>
主要活动:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.home_menu, menu);
item = menu.findItem(R.id.action_notifications);
if(loginStatus==false){
item.setVisible(false);
return false;
}
if(user!=null && !user.getUserType().equals("3")){
item.setVisible(false);
return false;
}
final View menu_hotlist = MenuItemCompat.getActionView(item);
TextView ui_hot =(TextView) menu_hotlist.findViewById(R.id.hotlist_hot);
ui_hot.setText(Integer.toString(13));
return true;
}
解决方法:
试试这个
item.setActionView(R.layout.counter_action_bar_notification_icon);
final View menu_hotlist = MenuItemCompat.getActionView(item);
TextView ui_hot =(TextView) menu_hotlist.findViewById(R.id.hotlist_hot);
ui_hot.setText(Integer.toString(13));
Angular 2:ngSwitch或ViewContainerRef.createComponent
<div *ngFor='let item of items'> <div [ngSwitch]="item.view"> <view-one *ngSwitchCase="'one'"></view-one> <view-two *ngSwitchCase="'two'"></view-two> <view-three *ngSwitchCase="'three'"></view-three> </div> </div>
我想知道是否有更好的更有效的方法,或者这是正确的方法吗?
我见过人们动态创建组件,但api已经改变了很多次,很难知道什么是正确的.似乎ViewContainerRef.createComponent()可能是另一种选择?
解决方法
这是我当前方法的简化形式:
@Component({ selector: "my-item",template: ` <div #placeholder></div> ` }) export class MyItemComponent implements AfterViewInit { @input() item: any; @ViewChild("placeholder",{read: ViewContainerRef}) placeholderRef: ViewContainerRef; constructor( private componentFactoryResolver: ComponentFactoryResolver) { } ngAfterViewInit() { switch(this.item.view) { case "one": this.loadItem(OneItemComponent); case "two": this.loadItem(TwoItemComponent); default: throw new Error("UnkNown item!"); } } private loadItem(component: Type<any>) { const factory = this.componentFactoryResolver.resolveComponentFactory(component); const componentRef = this.placeholderRef.createComponent(factory); componentRef.instance.item = this.item; componentRef.changeDetectorRef.detectChanges(); } }
现在您可以通过以下方式使用它:
<my-item *ngFor="let item of items" [item]="item"></my-item>
asp.net listview Container.DataItemIndex
<asp:Button ID="btnSave" runat="server" Text="Save" CommandName='<%# Eval("Section_Name")%>' CommandArgument='<%# Container.DataItemIndex %>' />
但我得到这个错误:
‘System.Web.UI.Control’不包含’DataItemIndex’的定义,并且没有可以找到接受类型’System.Web.UI.Control’的第一个参数的扩展方法’DataItemIndex'(你是否缺少using指令?或汇编参考?)
传递命令参数的正确方法是什么?
此按钮位于listview的itemtemplate中的内部和updatepanel.
谢谢,阿里
解决方法
我使用它
CommandArgument='<%#DataBinder.Eval(Container,"DataItemIndex")%>'
但是,我认为这两个建议也应该有效.
关于c# – TreeView.ItemContainerGenerator.ContainerFromItem为非根项目返回null.解决方法?的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于AbstractMultiTenantConnectionProvider 在 LocalContainerEntityManagerFactoryBean 中配置、android – MenuItemCompat.getActionView返回Null、Angular 2:ngSwitch或ViewContainerRef.createComponent、asp.net listview Container.DataItemIndex的相关信息,请在本站寻找。
本文标签: