コード例 #1
0
        }//Button Down method ends here

        private void ButtonUp(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("Button Up");

            Button      myButton    = sender as Button;
            Brush       buttonDark  = myButton.Background;
            Colorpicker colorPicker = new Colorpicker(buttonDark);

            myButton.Background = colorPicker.lighter();
        }//ButtonUp method ends here
コード例 #2
0
        public async Task InspirobotCommand()
        {
            HttpClient   client  = new HttpClient();
            var          piclink = await(await client.GetAsync("https://inspirobot.me/api?generate=true")).Content.ReadAsStringAsync();
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithAuthor("Here's your inspiration:", "https://inspirobot.me/website/images/inspirobot-dark-green.png", piclink);
            builder.WithImageUrl(piclink);
            var admin = await Context.Client.GetUserAsync(ulong.Parse(_config["AdminUserID"]));

            builder.WithFooter("Quote provided by inspirobot.me", admin.GetAvatarUrl());
            Colorpicker colorpicker = new Colorpicker();

            builder.WithColor(colorpicker.Pick());
            await ReplyAsync(null, false, builder.Build());
        }
コード例 #3
0
    public void Awake()
    {
        HoverData _hoverData = new HoverData();

        foreach (var item in _editModes)
        {
            item.Init(_hoverData);
        }

        _colorSelector.Init(_colorPicker);

        _layout.childControlHeight = false;
        _layout.childControlWidth  = false;

        if (_colorPicker == null)
        {
            _colorPicker = FindObjectOfType <Colorpicker>();
        }
        _colorPicker.Init();
    }
コード例 #4
0
    public void Init(Colorpicker colorpicker)
    {
        _colorPicker = colorpicker;
        if (_colorPicker == null)
        {
            _colorPicker = FindObjectOfType <Colorpicker>();
        }
        _borderColorTgl.onValueChanged.AddListener(delegate
        {
            _colorPicker.ShowColorpicker(true);
            IsAreaFill = false;
        });
        _fillAreaColorTgl.onValueChanged.AddListener(delegate
        {
            _colorPicker.ShowColorpicker(true);
            IsAreaFill = true;
        });

        _transparentBtn.onClick.AddListener(delegate { SetTransparentColor(); });
        _recentUsedBtn.onClick.AddListener(delegate { SetRecentUsedColor(); });

        Colorpicker.OnColorChanged += UpdateColor;
    }
コード例 #5
0
ファイル: 6UwU Command.cs プロジェクト: AtlantikTheWox/37bot
        public async Task UwUfyCommand(string uwuid = null)
        {
            IMessage messig = null;
            string   uwu    = new string(string.Empty);

            if (uwuid == null)
            {
                IEnumerable <IMessage> message = await Context.Channel.GetMessagesAsync(Context.Message, Direction.Before, 100).FlattenAsync();

                foreach (IMessage messag in message)
                {
                    if (!messag.Author.IsBot)
                    {
                        if (messag.Content != null && messag.Content != "")
                        {
                            if (!messag.Content.StartsWith("/37") && !messag.Content.StartsWith("!") && !messag.Content.StartsWith("+"))
                            {
                                uwu = messag.Content;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                var guilds = ((DiscordSocketClient)Context.Client).Guilds;
                foreach (SocketGuild guild in guilds)
                {
                    foreach (IMessageChannel channel in guild.TextChannels)
                    {
                        try
                        {
                            messig = await channel.GetMessageAsync(ulong.Parse(uwuid));
                        }
                        catch (Exception)
                        {
                        }
                        if (messig != null)
                        {
                            goto stop;
                        }
                    }
                }
                stop :;
                if (messig == null)
                {
                    await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> I'm sowwy, but i'm having twoubwe finding dat message, pwease twy again >w<");

                    return;
                }
                uwu = messig.Content;
            }

            string[] faces   = new string[] { "(・`ω´・)", ";;w;;", "owo", "UwU", ">w<", "^w^", "OwO", "UwU", "ÚwÚ", "^-^", ":3", "x3" };
            string[] actions = new string[] { @"\*blushes\*", @"\*whispers to self\*", @"\*cries\*", @"\*screams\*", @"\*sweats\*", @"\*runs away\*", @"\*screeches\*", @"\*walks away\*", @"\*looks at you\*", @"\*huggies tightly\*", @"\*boops your snoot\*" };
            uwu = Regex.Replace(uwu, "(?:r|l)", "w");
            uwu = Regex.Replace(uwu, "(?:R|L)", "W");
            uwu = Regex.Replace(uwu, "th([aeiouAEIOU])", "d$1");
            uwu = Regex.Replace(uwu, "Th([aeiouAEIOU])", "D$1");
            uwu = Regex.Replace(uwu, "TH([aeiouAEIOU])", "D$1");
            uwu = Regex.Replace(uwu, "na", "nya");
            uwu = Regex.Replace(uwu, "Na", "Nya");
            uwu = Regex.Replace(uwu, "NA", "NYA");
            uwu = Regex.Replace(uwu, "ove ", "uv");
            var words = uwu.Split(" ");

            for (int i = 0; i < words.Length; i++)
            {
                if (new Random().Next(11) == 3)
                {
                    char start = words[i].ToCharArray()[0];
                    words[i] = start + "-" + words[i];
                }
                else if (new Random().Next(51) == 11)
                {
                    words[i] = faces[new Random().Next(faces.Length)] + " " + words[i];
                }
                else if (new Random().Next(150) == 69)
                {
                    words[i] = actions[new Random().Next(actions.Length)] + " " + words[i];
                }
            }
            uwu  = string.Join(" ", words);
            uwu += $" {faces[new Random().Next(faces.Length)]}";
            EmbedBuilder builder = new EmbedBuilder();

            builder.WithAuthor(messig.Author.Username + "#" + messig.Author.Discriminator, messig.Author.GetAvatarUrl());
            builder.WithDescription(uwu);
            Colorpicker picker = new Colorpicker();

            builder.WithColor(picker.Pick());
            await Context.Channel.SendMessageAsync("", false, builder.Build());
        }
コード例 #6
0
ファイル: MemeCommand.cs プロジェクト: AtlantikTheWox/37bot
        public async Task MemeCommandAsync(string mp3 = null, [Remainder] string user = null)
        {
            Authorisationcheck authorisationcheck = new Authorisationcheck();

            if (!authorisationcheck.Check(Context.User.Id, _config))
            {
                return;
            }

            if (mp3 == null || user == null)
            {
                await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> You need to provide a sound as well as a username");

                return;
            }
            if (!File.Exists($"audio/{mp3}.wav"))
            {
                await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> I'm sorry, but the audio file you requested doesnt exist (yet)");

                return;
            }

            string id       = null;
            string username = "";
            var    guilds   = _client.Guilds;

            foreach (SocketGuild guild in guilds)
            {
                foreach (SocketUser user1 in guild.Users)
                {
                    if (user1.Username.ToLower() == user.ToLower())
                    {
                        id       = user1.Id.ToString();
                        username = user1.Username;
                    }
                }
            }
            if (id == null)
            {
                await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> I'm having trouble finding that user, please try again");

                return;
            }

            File.WriteAllText($"prank/{id}.37", mp3);
            await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> Successfully queued the user for a meme!");

            EmbedBuilder builder = new EmbedBuilder();

            builder.WithFooter("No copyright infringement intended Kappa", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
            var    tfile  = TagLib.File.Create($"audio/{mp3}.wav");
            string song   = tfile.Tag.Title;
            string artist = tfile.Tag.Performers.FirstOrDefault();
            string thumb  = tfile.Tag.Comment;

            builder.WithThumbnailUrl(thumb);
            builder.WithTitle($"Queued meme for user **{username}**");
            builder.WithDescription($"**{song}** by **{artist}**");
            Colorpicker picker = new Colorpicker();

            builder.WithColor(picker.Pick());
            await Context.Channel.SendMessageAsync("", false, builder.Build());
        }
コード例 #7
0
        public async Task LeaderboardCommand()
        {
            DirectoryInfo               di   = new DirectoryInfo("leaderboard");
            Dictionary <long, int>      temp = new Dictionary <long, int>();
            List <Tuple <string, int> > d    = new List <Tuple <string, int> >();

            foreach (FileInfo file in di.GetFiles())
            {
                temp.Add(long.Parse(file.Name.Replace(".37", "")), int.Parse(File.ReadAllText($"leaderboard/{file.Name}")));
            }
            foreach (KeyValuePair <long, int> kvp in temp)
            {
                string username = null;

                var user = _client.GetUser((ulong)kvp.Key);

                if (user == null)
                {
                    var farsearch = await rclient.GetUserAsync((ulong)kvp.Key);

                    if (farsearch == null)
                    {
                        username = "******";
                    }
                    else
                    {
                        username = farsearch.Username;
                    }
                }
                else
                {
                    username = user.Username;
                }
                Tuple <string, int> entry = new Tuple <string, int>(username, kvp.Value);
                d.Add(entry);
            }
            var          leaderboard = from entry in d orderby entry.Item2 descending select entry;
            EmbedBuilder builder     = new EmbedBuilder();
            string       lb          = "";
            int          b           = 1;

            builder.WithAuthor("37Gang-Leaderboard", "https://cdn.discordapp.com/app-icons/737060692527415466/c64109fbdff1a1f6dfd7515eaec5198d.png?size=512", "https://bit.ly/37status");
            builder.WithFooter("Accuracy of these values can not be guaranteed", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
            foreach (Tuple <string, int> kvp in leaderboard)
            {
                string count;
                if (kvp.Item2 == 1)
                {
                    count = "37";
                }
                else
                {
                    count = "37s";
                }
                lb = lb + "\n" + b + $". {kvp.Item1} ({kvp.Item2} {count})";
                b++;
            }
            Colorpicker picker = new Colorpicker();

            builder.WithColor((uint)picker.Pick());
            builder.WithDescription(lb);
            await Context.Channel.SendMessageAsync("", false, builder.Build());
        }
コード例 #8
0
        public async Task AuthorizeCommand(string option = null, [Remainder] long args = 0)
        {
            switch (option)
            {
            case "add":
                if (args == 0)
                {
                    await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> You need to provide a user id");

                    break;
                }
                if (File.Exists($"authorized/{args}.37"))
                {
                    await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> This user is already authorized");

                    break;
                }
                File.Create($"authorized/{args}.37");
                await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> Success");

                break;

            case "remove":
                if (args == 0)
                {
                    await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> You need to provide a user id");

                    break;
                }
                if (!File.Exists($"authorized/{args}.37"))
                {
                    await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> This user isn't authorized");

                    break;
                }
                File.Delete($"authorized/{args}.37");
                await Context.Channel.SendMessageAsync($"<@{Context.User.Id}> Success");

                break;

            case "list":
                DirectoryInfo di      = new DirectoryInfo("authorized");
                EmbedBuilder  builder = new EmbedBuilder();
                string        list    = "";
                foreach (FileInfo file in di.GetFiles())
                {
                    string id                   = file.Name.Replace(".37", "");
                    string username             = "******";
                    DiscordSocketClient _client = (DiscordSocketClient)Context.Client;
                    var guildList               = _client.Guilds;
                    foreach (SocketGuild guild in guildList)
                    {
                        foreach (SocketUser user in guild.Users)
                        {
                            if (Convert.ToString(user.Id) == id)
                            {
                                username = user.Username + "#" + user.Discriminator;
                                goto stop;
                            }
                        }
                    }
                    stop :;
                    list = list + "\n" + id + " - " + username;
                }
                if (list == "")
                {
                    list = "No people have been authorized yet";
                }
                builder.WithAuthor("37 Authorisation list", "https://cdn.discordapp.com/app-icons/737060692527415466/c64109fbdff1a1f6dfd7515eaec5198d.png?size=512", "https://bit.ly/37status");
                builder.WithDescription(list);
                builder.WithFooter($"No responsibility is accepted for the accuracy of this information.", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
                Colorpicker picker = new Colorpicker();
                builder.WithColor(picker.Pick());
                await Context.Channel.SendMessageAsync(null, false, builder.Build());

                break;

            default:
                return;
            }
        }
コード例 #9
0
        public async Task Help()
        {
            List <CommandInfo> commands     = Cservice.Commands.ToList();
            EmbedBuilder       embedBuilder = new EmbedBuilder();

            embedBuilder.WithAuthor("37 Help", "https://cdn.discordapp.com/app-icons/737060692527415466/c64109fbdff1a1f6dfd7515eaec5198d.png?size=512", "https://bit.ly/37status");
            foreach (CommandInfo command in commands)
            {
                // Get the command Summary attribute information
                if (command.Remarks == "all")
                {
                    string embedFieldText = command.Summary ?? "No description available\n";
                    embedBuilder.AddField(command.Name, embedFieldText, true);
                }
            }
            Authorisationcheck check = new Authorisationcheck();

            if (check.Check(Context.User.Id, _config))
            {
                embedBuilder.AddField("Admin Commands", "You have access to these command because you're authorized", false);
                foreach (CommandInfo command in commands)
                {
                    if (command.Remarks == "authorized")
                    {
                        string embedFieldText = command.Summary ?? "No description available\n";
                        embedBuilder.AddField(command.Name, embedFieldText, true);
                    }
                }
            }
            if (Context.User.Id.ToString() == _config["AdminUserID"])
            {
                embedBuilder.AddField("Owner Commands", "You have access to these command because you're the bot's owner", false);
                foreach (CommandInfo command in commands)
                {
                    if (command.Remarks == "owner")
                    {
                        string embedFieldText = command.Summary ?? "No description available\n";
                        embedBuilder.AddField(command.Name, embedFieldText, true);
                    }
                }
            }
            var    guildList = _client.Guilds;
            string admin     = "";

            foreach (SocketGuild guild in guildList)
            {
                foreach (SocketUser user in guild.Users)
                {
                    if (Convert.ToString(user.Id) == _config["AdminUserID"])
                    {
                        admin = user.Username + "#" + user.Discriminator;
                        goto stop;
                    }
                }
            }
            stop :;
            Colorpicker colorpicker = new Colorpicker();

            embedBuilder.WithColor(colorpicker.Pick());
            embedBuilder.WithFooter($"If you encounter any issues contact {admin}", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
            await ReplyAsync(null, false, embedBuilder.Build());
        }
コード例 #10
0
        public async Task VCCommand(string sound = null)
        {
            if (sound == "list")
            {
                EmbedBuilder builder = new EmbedBuilder();
                builder.WithAuthor("37 vc sounds", "https://cdn.discordapp.com/app-icons/737060692527415466/c64109fbdff1a1f6dfd7515eaec5198d.png?size=512", "https://bit.ly/37status");
                builder.WithFooter("No copyright infringement intended Kappa", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
                DirectoryInfo di = new DirectoryInfo("audio");
                foreach (FileInfo file in di.GetFiles())
                {
                    if (file.Name != "hawwy.wav")
                    {
                        var    tfile  = TagLib.File.Create($"audio/{file.Name}");
                        string name   = file.Name.Replace(".wav", "");
                        string song   = tfile.Tag.Title;
                        string artist = tfile.Tag.Performers.FirstOrDefault();
                        builder.AddField(name, $"**{song}** by **{artist}**");
                    }
                }
                Colorpicker picker = new Colorpicker();
                builder.WithColor((uint)picker.Pick());
                await Context.Channel.SendMessageAsync("", false, builder.Build());

                return;
            }
            if ((Context.User as IVoiceState).VoiceChannel == null || Context.Guild.Id != (Context.User as IVoiceState).VoiceChannel.GuildId)
            {
                await Context.Channel.SendMessageAsync("You need to be in a vc on this server to use the vc command 🤪");

                return;
            }
            var          guild = (Context.User as IVoiceState).VoiceChannel.Guild;
            var          def   = new Tuple <IAudioClient, Process>(null, null);
            IAudioClient connection;

            try
            {
                connection = _connections.GetValueOrDefault(guild.Id).Item1;
            }
            catch (System.NullReferenceException)
            {
                connection = null;
            }
            if (sound == "dc")
            {
                if (connection != null && connection.ConnectionState == Discord.ConnectionState.Connected)
                {
                    if ((Context.User as IVoiceState).VoiceChannel == null)
                    {
                        await Context.Channel.SendMessageAsync("You need to be in the same vc as the bot to use this command!");

                        return;
                    }
                    else
                    {
                        await(Context.User as IVoiceState).VoiceChannel.DisconnectAsync();
                        if (_connections.GetValueOrDefault(guild.Id).Item2 != null)
                        {
                            _connections.GetValueOrDefault(guild.Id).Item2.Kill();
                            Tuple <IAudioClient, Process> te = new Tuple <IAudioClient, Process>(connection, null);
                            _connections[((SocketVoiceChannel)((Context.User as IVoiceState).VoiceChannel)).Guild.Id] = te;
                        }
                        await Context.Channel.SendMessageAsync("Disconnected!");

                        return;
                    }
                }
                else
                {
                    await Context.Channel.SendMessageAsync("You cant disconnect the bot if its not connected 🤪");

                    return;
                }
            }
            if (connection != null && connection.ConnectionState == Discord.ConnectionState.Connected)
            {
                await Context.Channel.SendMessageAsync("Sorry, but i cant be in 2 channels at once");

                return;
            }
            if (connection == null || connection.ConnectionState != Discord.ConnectionState.Connected)
            {
                if (sound == null)
                {
                    sound = "hawwy";
                }
                if (sound == "random")
                {
                    DirectoryInfo di   = new DirectoryInfo("audio");
                    var           r    = new Random();
                    int           rand = r.Next(di.GetFiles().Count());
                    sound = di.GetFiles()[rand].Name.Replace(".wav", "");
                }
                if (!File.Exists($"audio/{sound.ToLower()}.wav"))
                {
                    await Context.Channel.SendMessageAsync("I'm sorry, but i dont know that sound (yet). Check \"/37 vc list\" for a list of available sounds or ask my owner to add the sound you wanted");

                    return;
                }
                try
                {
                    Console.WriteLine($"Connecting to channel {((Context.User as IVoiceState)).VoiceChannel.Id}");
                    var audioclient = await(Context.User as IVoiceState).VoiceChannel.ConnectAsync();
                    Console.WriteLine($"Connected to channel {((SocketVoiceChannel)((Context.User as IVoiceState).VoiceChannel)).Id}");
                    Tuple <IAudioClient, Process> t = new Tuple <IAudioClient, Process>(audioclient, null);
                    _connections[((SocketVoiceChannel)((Context.User as IVoiceState).VoiceChannel)).Guild.Id] = t;
                    connection = audioclient;
                    await Task.Delay(1000);
                }
                catch (Exception ex)
                {
                    // Oh no, error
                    Console.WriteLine(ex.Message);
                    Console.WriteLine($"- {ex.StackTrace}");
                }
                EmbedBuilder builder = new EmbedBuilder();

                builder.WithFooter("No copyright infringement intended Kappa", "https://cdn.discordapp.com/avatars/329650083819814913/33b46ac7c4bfa97c6df65b108fd8c008.png?size=512");
                var    tfile  = TagLib.File.Create($"audio/{sound}.wav");
                string song   = tfile.Tag.Title;
                string artist = tfile.Tag.Performers.FirstOrDefault();
                string thumb  = tfile.Tag.Comment;
                builder.WithThumbnailUrl(thumb);
                builder.WithTitle($"Now playing");
                builder.WithDescription($"**{song}** by **{artist}**");
                Colorpicker picker = new Colorpicker();
                builder.WithColor(picker.Pick());
                await Context.Channel.SendMessageAsync("", false, builder.Build());


                try
                {
                    await connection.SetSpeakingAsync(true); // send a speaking indicator

                    var psi = new ProcessStartInfo
                    {
                        FileName  = "ffmpeg",
                        Arguments = $@"-re -i ""audio/{sound}.wav"" -ac 2 -f s16le -ar 48000 pipe:1",
                        RedirectStandardOutput = true,
                        UseShellExecute        = false
                    };
                    var ffmpeg = Process.Start(psi);
                    Tuple <IAudioClient, Process> t = new Tuple <IAudioClient, Process>(connection, ffmpeg);
                    _connections[((SocketVoiceChannel)((Context.User as IVoiceState).VoiceChannel)).Guild.Id] = t;
                    var output  = ffmpeg.StandardOutput.BaseStream;
                    var discord = connection.CreatePCMStream(AudioApplication.Voice);
                    await output.CopyToAsync(discord);

                    await discord.FlushAsync();

                    Tuple <IAudioClient, Process> te = new Tuple <IAudioClient, Process>(connection, null);
                    _connections[((SocketVoiceChannel)((Context.User as IVoiceState).VoiceChannel)).Guild.Id] = te;

                    await connection.SetSpeakingAsync(false); // we're not speaking anymore
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine($"- {ex.StackTrace}");
                }
                try
                {
                    await((SocketVoiceChannel)(Context.User as IVoiceState).VoiceChannel).DisconnectAsync();
                }
                catch (NullReferenceException)
                {
                }
            }
        }
コード例 #11
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var property = value as CustomProperty;

            if (property != null)
            {
                switch (property.PropertyType)
                {
                case CustomPropertyType.Number:
                    NumericUpDown numericUpDown = new NumericUpDown();
                    numericUpDown.Minimum     = property.RangeMin;
                    numericUpDown.Maximum     = property.RangeMax;
                    numericUpDown.DataContext = property;
                    numericUpDown.SetBinding(NumericUpDown.ValueProperty, "Value");
                    return(numericUpDown);

                case CustomPropertyType.String:
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);

                case CustomPropertyType.Color:
                    var colorpicker = new Colorpicker();
                    colorpicker.DataContext = property;
                    colorpicker.SetBinding(Colorpicker.SelectedColorProperty, new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(colorpicker);

                case CustomPropertyType.ValueList:
                {
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Variable:
                {
                    property.InitVaribleList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.View:
                {
                    property.InitViewList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Icon:
                    var iconicker = new IconPicker();
                    iconicker.DataContext = property;
                    iconicker.SetBinding(IconPicker.SelectedIconProperty, new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(iconicker);

                case CustomPropertyType.Bool:
                    CheckBox checkBox = new CheckBox();
                    checkBox.DataContext = property;
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, "Value");
                    return(checkBox);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(null);
        }
コード例 #12
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var property = value as CustomProperty;

            if (property != null)
            {
                switch (property.PropertyType)
                {
                //case CustomPropertyType.Number:
                //    NumericUpDown numericUpDown = new NumericUpDown();
                //    numericUpDown.Minimum = property.RangeMin;
                //    numericUpDown.Maximum = property.RangeMax;
                //    numericUpDown.DataContext = property;
                //    numericUpDown.SetBinding(NumericUpDown.ValueProperty, "Value");
                //    return numericUpDown;
                case CustomPropertyType.Code:
                case CustomPropertyType.String:
                case CustomPropertyType.Number:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);
                }

                case CustomPropertyType.ParamString:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);
                }

                case CustomPropertyType.Color:
                    var colorpicker = new Colorpicker();
                    colorpicker.DataContext = property;
                    colorpicker.SetBinding(Colorpicker.SelectedColorProperty,
                                           new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(colorpicker);

                case CustomPropertyType.ValueList:
                {
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Variable:
                {
                    property.InitVaribleList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.View:
                {
                    property.InitViewList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Icon:
                    var iconicker = new IconPicker();
                    iconicker.DataContext = property;
                    iconicker.SetBinding(IconPicker.SelectedIconProperty,
                                         new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(iconicker);

                case CustomPropertyType.Bool:
                    CheckBox checkBox = new CheckBox();
                    checkBox.DataContext = property;
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, "Value");
                    return(checkBox);

                case CustomPropertyType.File:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    text.HorizontalAlignment      = HorizontalAlignment.Stretch;
                    text.VerticalContentAlignment = VerticalAlignment.Center;
                    text.Margin = new Thickness(0, 0, 50, 0);
                    Button button = new Button();
                    button.HorizontalAlignment = HorizontalAlignment.Right;
                    button.Content             = "...";
                    button.Click += (sender, e) =>
                    {
                        OpenFileDialog dialog = new OpenFileDialog();
                        if (dialog.ShowDialog() == true)
                        {
                            property.Value = dialog.FileName;
                        }
                    };
                    var stackpanel = new Grid {
                        HorizontalAlignment = HorizontalAlignment.Stretch
                    };
                    stackpanel.Children.Add(text);
                    stackpanel.Children.Add(button);
                    return(stackpanel);
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(null);
        }