wpf tabcontrol:根据选定的选项卡更改通用选项卡的内容

时间:2016-12-21 10:28:46

标签: c# wpf xaml tabs tabcontrol

MainWindow.xaml:

class SignUp: NSObject
{
    class func registerWithAPI(firstName: String, lastName:String, completionHandler: @escaping (_ Result:AnyObject?, _ Error:NSError?) -> Void)
    {
        let dict = NSMutableDictionary()

        if !firstName.isEmpty
        {
           dict.setValue(firstName, forKey: "firstname")
        }
        if !lastName.isEmpty
        {
            dict.setValue(lastName, forKey: "lastname")
        }

        APIManager.postAPI(FV_API.apiSignUP, parameters: dict)
        {
            (Result, Error) -> Void in
            completionHandler(Result, Error)
        }
    }
}

tab1.xaml:

func apiForSignup()
    {
        SignUp.registerWithAPI(firstName: txtFieldFirstName.text!, lastName: txtFieldLastName.text!)
        {
            (Result, Error) -> Void in
            // write code
}

GenericTab.xaml:

WM_PAINT

如何实现以下行为: 如果在MainWindow中选择了tab1,则GenericTab.Button-Content应为例如" hello tab1"如果选择tab2,Generictab.Button-Content应为" hello tab2" ?

1 个答案:

答案 0 :(得分:1)

您可以设置TabItem的Tag属性,然后将Button的Content属性绑定到此属性。

<强> MainWindow.xaml:

<TabControl TabStripPlacement="Left">
    <TabItem Header="Tab1" Tag="hello tab1">
        <usercontrol:GenericTab />
    </TabItem>
    <TabItem Header="Tab2" Tag="hello tab2">
        <usercontrol:GenericTab />
    </TabItem>
</TabControl>

<强> GenericTab.xaml:

<Button Name="btn_Button" Content="{Binding Path=Tag, RelativeSource={RelativeSource AncestorType=TabItem}}" Command="{Binding ClickCommand}" ></Button>