从Control转换为Func <control> for TabbedView - Devexpress Windows Form

时间:2018-04-20 09:39:31

标签: c# windows forms devexpress

我正在将Devexpress用于Windows窗体应用。 所以我想替换这个片段:

import UIKit
import PlaygroundSupport

let rect = CGRect(x: 0,y: 0, width: 300, height: 400)
let view = UIView(frame: rect)
view.backgroundColor = UIColor.yellow
PlaygroundPage.current.liveView = view

let layer = CALayer()
layer.backgroundColor = UIColor.red.cgColor
layer.frame = CGRect(x: 75, y: 75, width: 150, height: 150)
view.layer.addSublayer(layer)

layer.cornerRadius = 15
let animation = CABasicAnimation(keyPath:#keyPath(CALayer.cornerRadius))
animation.toValue = layer.bounds.width / 2
animation.duration = 1
layer.add(animation, forKey: nil)

使用此代码段:

tabbedView.AddDocument(userControl);
tabbedView.ActivateDocument(userControl);

此处的问题是此方法请求tabbedView.AddOrActivateDocument(doc => doc.Caption == e.Element.Name, userControl); 而不是Func<Control>

我找到了Control文档和规范,但找不到如何从Func<Object,Object>转换为Object

感谢您的帮助。谢谢。

1 个答案:

答案 0 :(得分:1)

public Func<Control> getControl = () => new Control(); 表示它不接受任何参数并返回一个Control,类似于

tabbedView.AddOrActivateDocument(doc => doc.Caption == e.Element.Name, () => userControl);

您可以通过传递lambda表达式来解决此问题。试试这个

from tkinter import *
from tkinter import messagebox
import tkinter.filedialog
from tkinter.filedialog import askdirectory
import requests
import simplejson as json
import os

#from json import JSONEncoder


#class MyEncoder(JSONEncoder):
    #def default(self, o):
         #return o.__dict__    


#Connect to API function

def apiconnect(statusvar):

    ticektid = e1.get()

    def to_serializable(ticketid):
        return str(ticketid)

    url = "https://staging3.activitar.com/ticket_api/tickets"
    data = {'ticket_id':e1.get(),'direction': 'up'}
    headers = {'Content-Type': 'application/json','Authorization' :'J0XDvDqVRy9hMF9Fo7j5'}
    r = requests.post(url,data=json.dumps(data), headers=headers)
    requestpost = requests.post(url, headers=headers, json=data)
    response_data = requestpost.json()
    statusvar = (response_data["status"])
    messagevar = (response_data["message"])
    json.dumps(url,data)
   # MyEncoder().encode(ticketid)
    #'{"ticekt_id": "/foo/bar"}'
#19 February 2018
#def from_json(json_object):
  #  if 'ticket_id' in json_object:
       # return FileItem(json_object['ticket_id'])
       # ticketid = JSONDecoder(object_hook = from_json).decode('{"ticket_id": "/foo/bar"}')

#Including GPIO config 
    if statusvar == "failed":
        messagebox.showinfo("Cape Point", messagevar)

    else: statusvar == "successful"



#Run at full screen automatically:
#---------------Function & Class--------------------------------#
class FullScreenApp(object):
    def __init__(self, master, **kwargs):
        self.master=master
        pad=3
        self._geom='200x200+0+0'
        master.geometry("{0}x{1}+0+0".format(
            master.winfo_screenwidth()-pad, master.winfo_screenheight()-pad))
        master.bind('<Escape>',self.toggle_geom)            
    def toggle_geom(self,event):
        geom=self.master.winfo_geometry()
        print(geom,self._geom)
        self.master.geometry(self._geom)
        self._geom=geom
#--------------------------------------------------------------------#

        def next_img():
            img_label.img = PhotoImage(file=next(imgs))
            img_label.config(image=img_label.img)

#create a textbox on a form
root = Tk()

#-----Full Screen-------#
app = FullScreenApp(root)


root.title("Cape Point")
root.configure(background = 'White')