怎么用作代码?

时间:2018-05-14 19:59:58

标签: c#

嗨我写完了一个正常工作的代码;

private void baslangic_gridler(UIElement element)
    {
        DoubleAnimation opaklk = new DoubleAnimation();
        opaklk.From = 0;
        opaklk.To = 1;
        opaklk.Duration = new TimeSpan(0, 0, 0, 0, 300);


        Thickness to_margin = (element as Grid).Margin;
        Thickness from_margin = to_margin;


        from_margin.Left = from_margin.Left - 25;
        ThicknessAnimation kaydır = new ThicknessAnimation();
        kaydır.From = from_margin;
        kaydır.To = to_margin;
        kaydır.Duration = new TimeSpan(00,0,0,0,300);


        element.BeginAnimation(MarginProperty, kaydır);
        element.BeginAnimation(OpacityProperty, opaklk);
    }

但我想使用所有类型的表单元素,如按钮或图像

Thickness to_margin = (element as Grid).Margin;

我可以使用什么代替网格来代替所有元素?

1 个答案:

答案 0 :(得分:3)

MSDNlet loginForm = document.querySelector('.login-form'); let usernameField = document.getElementById('username-field'); let passwordField = document.getElementById('password-field'); // submit login form to server using ajax function ajaxFormSubmit() { 'use strict'; let ajaxRequest = new XMLHttpRequest(); let url = 'admin login.php'; // login form submitted on server successfully ajaxRequest.onload = function () { if (ajaxRequest.readyState === 4 && ajaxRequest.status === 200) { console.log(ajaxRequest.responseText); displayInfoMessage(ajaxRequest.responseText, 'success'); } }; // error while login form submission on server ajaxRequest.onerror = function () { if (ajaxRequest.status !== 200) { console.log(ajaxRequest.responseText); displayInfoMessage(ajaxRequest.responseText, 'error'); } }; ajaxRequest.open('POST', url, true); ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.send(new FormData(loginForm)); } function validateForm(e) { 'use strict'; // prevent form submission e.preventDefault(); if (anyEmptyField()) { displayInfoMessage('Please fill all the empty fields', 'error'); highLightEmptyFields(); //return false; return; } // check if username is in right format if (!(regexTester(/^[A-Za-z0-9_]+$/g, usernameField.value))) { displayInfoMessage('Username not valid', 'error'); highLightTextField(usernameField); //return false; return; } // check if username is atleast 3 characters long if (usernameField.value.length < 3) { displayInfoMessage('Username should contain atleast 3 characters', 'error'); highLightTextField(usernameField); //return false; return; } // check if password is in right format if (!(regexTester(/^[A-Za-z0-9_]+$/g, passwordField.value))) { displayInfoMessage('Password not valid', 'error'); highLightTextField(passwordField); //return false; return; } // check if password is atleast 6 characters long if (passwordField.value.length < 6) { displayInfoMessage('Password should contain atleast 6 characters', 'error'); highLightTextField(passwordField); //return false; return; } //return true; // submit form information to server via ajax ajaxFormSubmit(); } // add submit event listener on login form loginForm.addEventListener('submit', validateForm); 类(System.Windows.Controls)从Grid继承它的Margin属性,因此您应该使用它来覆盖所有你的基地。

  

Margin:获取或设置元素的外边距。(继承自FrameworkElement。)

请注意,FrameworkElement FrameworkElement,因此您可以将UIElement作为参数添加到您的方法而不是FrameworkElement像这样:

UIElement