我尝试为启用或禁用 WPF 按钮设置通用样式:
<Style x:Name="btnStyle" x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="#FFFFFFFF"/>
<Setter Property="BorderBrush" Value="#FFCFFFFF"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Style" Value="{DynamicResource btnStyle}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Style" Value="{DynamicResource btnStyle}" />
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
和我的按钮:
<Button Style="{StaticResource btnStyle}"/>
Run Code Online (Sandbox Code Playgroud)
这会在运行时生成以下异常。
"Style object is not allowed to affect the Style property of the object to which it applies."
Run Code Online (Sandbox Code Playgroud)
如何将这种通用样式应用于按钮的两种状态?我可以在不覆盖按钮模板的情况下只使用样式吗?
我很难回答如何使用 CSS 执行此按钮。最简单的方法是使用 :after 和右侧部分的背景图像,但这在悬停效果方面并不美观和干净。
我已经能够用右边的蓝色箭头自己解决它,但是这个“双箭头”让我发疯了。
我尝试创建一个在同一个按钮上启动和停止的 MediaPlayer,如下所示:
public void song1(View view){
if(mp.isPlaying() == true){
mp.pause();
}else{
mp = MediaPlayer.create(this, R.raw.song1);
mp.start();
}
}
Run Code Online (Sandbox Code Playgroud)
但我的应用程序崩溃,如果我尝试按一下按钮,所以我souroundet它try和Catch这样的:
public void song1(View view){
try{
if(mp.isPlaying() == true){
mp.pause();
}else{
mp = MediaPlayer.create(this, R.raw.song1);
mp.start();
}
}catch (Exception e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
这是 Logcat:
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.media.MediaPlayer.isPlaying()' on a null object reference
W/System.err: at com.example.exampleapp.MainActivity.sound1(MainActivity.java:129)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
W/System.err: at android.view.View.performClick(View.java:5264)
W/System.err: at android.view.View$PerformClick.run(View.java:21297)
W/System.err: at android.os.Handler.handleCallback(Handler.java:743) …Run Code Online (Sandbox Code Playgroud) <input type="submit" id="edit-save-m" name="save_m" value="Save my thing" class="form-submit ajax-processed saved-m-processed">
Run Code Online (Sandbox Code Playgroud)
如果按钮被禁用,我需要使用 Python 和 Selenium 进行验证。有任何想法吗?
我需要帮助制作一个看起来像这样的按钮:
无论按钮的大小如何,它都应该有那些圆角。
到目前为止我所拥有的:
App.xaml 中按钮的样式
<!-- Standard Button Colors-->
<SolidColorBrush x:Key="StandardButtonBackground" Color="#1C536F" />
<SolidColorBrush x:Key="StandardButtonForeground" Color="#FEFEFE" />
<!-- Standard Button Template-->
<Style x:Key="StandardButton" TargetType="Button">
<Setter Property="Background" Value="{StaticResource StandardButtonBackground}" />
<Setter Property="Foreground" Value="{StaticResource StandardButtonForeground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="55" Background="{StaticResource StandardButtonBackground}">
<ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
在视图中使用:
<Button Style="{StaticResource StandardButton}" Content="Test" FontSize="20"/>
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
但是角是像素大小的,所以当按钮的大小改变时,角不会相应地改变。
接下来是这条彩色线,它应该显示一个状态。我怎样才能添加这样的一行?
我知道拖放按钮很容易,但是讲师坚持以编程方式创建按钮。
在 Form1_Load 方法中,我应该编写什么代码来创建一个简单的按钮?
private void Form1_Load(object sender, System.EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
所以在加载按钮会显示?
当我按下带有InlineKeyboardButton. 我正在尝试以下但没有运气:
bot.send_message(chat_id=chat_id,
text='/help',
parse_mode=telegram.ParseMode.HTML)
Run Code Online (Sandbox Code Playgroud) 我创建了一个新的使用作出反应的应用程序npx create-react-app test,然后我安装使用rsuitenpm install rsuite和进口Button和ButtonGroup和index.less文件:
import React from 'react';
import { Button, ButtonGroup } from 'rsuite';
// import default style
import 'rsuite/styles/less/index.less'; // or 'rsuite/dist/styles/rsuite.min.css'
function App() {
return (
<div className="App">
<ButtonGroup>
<Button>
Hey
</Button>
<Button>
asd
</Button>
</ButtonGroup>
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
但是按钮没有样式,而是显示如下:
我究竟做错了什么?