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" ?
答案 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>